将 ListViewItem 添加到 WPF 中已数据绑定的 ListView

发布于 2024-10-17 02:27:50 字数 933 浏览 5 评论 0原文

我目前正在制作一个销售点,我让它在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恬淡成诗 2024-10-24 02:27:50

我认为你应该使用 ListBox 而不是 ListViewDataTemplateSelector

创建基本抽象类和 2 个子类,例如:BaseListItemProductListItemDiscountListItem< /代码>。然后将特定位置的特定对象插入 ObservableCollection 中,用作 ListBoxItemsSource

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文