开发者

Adding a ListViewItem to an already data-bound ListView in WPF

I'm currently working on making a point of sale and I got it to show items in a ListView that are in the current sale. I did this by DataBinding an ObservableCollection of "Item"-type objects in a static "Sale" class called CurrentSale. Not bad, eh? But I need to add coupons and discounts to my pos now, and it's proving to be difficult with the way WPF is set up.

This: http://dl.dropbox.com/u/1330689/listnow.jpg is how the listview currently looks. This: http开发者_运维问答://dl.dropbox.com/u/1330689/listgoal.jpg is my mockup of how I'd like a discount to show up. I think I've got the discount and coupon part of the program under control, I'd just like to make them show up. I'd be super thrilled if someone could show me some sample code demonstrating how to insert a custom listviewitem into a listview that's already bound with data, and with similar characteristics(multiple cells, black background)

I read through this: Append Items to Databound ItemsControl in WPF and it looks like that guy's got a similar problem. The solutions given to him were to add a special item to the bound list, or to use a CompositeCollection. I can't add a "special" item to the observablecollection, because it doesn't let me change the background color, and I wanted a cleaner solution. Also, I couldn't really find any documentation on CompositeCollections with ListViews, so maybe somebody can shed more light on it(if it's relevant to my problem)

Thanks :)


I think you should use ListBox instead of ListView and DataTemplateSelector

Create base abstract class and 2 subclasses, for instance: BaseListItem, ProductListItem and DiscountListItem. Then insert specific object in the specific place into ObservableCollection<BaseListItem> used as ItemsSource for your ListBox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜