将 ListViewItem 添加到 WPF 中已数据绑定的 ListView
我目前正在制作一个销售点,我让它在 ListView 中显示当前销售中的商品。我通过在名为 CurrentSale 的静态“Sale”类中对“Item”类型对象的 ObservableCollection 进行数据绑定来完成此操作。不错吧?但我现在需要向我的 pos 添加优惠券和折扣,事实证明 WPF 的设置方式很困难。
这: http://dl.dropbox.com/u/1330689/listnow.jpg 是列表视图当前的样子。这: http://dl.dropbox.com/u/1330689/listgoal.jpg 是我希望如何显示折扣的模型。我想我已经控制了该计划的折扣和优惠券部分,我只想让它们出现。如果有人可以向我展示一些示例代码,演示如何将自定义列表视图项插入到已经与数据绑定的列表视图中,并且具有类似的特征(多个单元格,黑色背景),我会非常兴奋
我读过以下内容: 将项目附加到 WPF 中的 Databound ItemsControl 看来那个人也有类似的问题。给他的解决方案是向绑定列表中添加一个特殊项目,或者使用 CompositeCollection。我无法将“特殊”项目添加到可观察集合中,因为它不允许我更改背景颜色,而且我想要一个更干净的解决方案。另外,我真的找不到任何关于带有 ListViews 的 CompositeCollections 的文档,所以也许有人可以提供更多信息(如果它与我的问题相关)
谢谢:)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该使用
ListBox
而不是ListView
和 DataTemplateSelector创建基本抽象类和 2 个子类,例如:
BaseListItem
、ProductListItem
和DiscountListItem< /代码>。然后将特定位置的特定对象插入
ObservableCollection
中,用作ListBox
的ItemsSource
。I think you should use
ListBox
instead ofListView
and DataTemplateSelectorCreate base abstract class and 2 subclasses, for instance:
BaseListItem
,ProductListItem
andDiscountListItem
. Then insert specific object in the specific place intoObservableCollection<BaseListItem>
used asItemsSource
for yourListBox
.