【发布时间】:2017-01-20 17:09:24
【问题描述】:
我有一个项目集合,已绑定到 ItemsControl:
<ItemsControl ItemsSource="{Binding ProductCategories, Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TextBlock Text="{Binding CategoryName}"/>
</ToggleButton>
然后我有第二个项目集合,在我的视图模型中,它基于一个查询,依赖于上述集合。
所以,我的要求是根据上述类别过滤产品列表。我遇到的问题是上面的绑定是到 ProductCategory 的;因此,虽然该集合为 ProductCategory 上的“IsSelected”属性正确触发,但它不会通知“ProductCategories”已更改。
ProductCategories 定义为:
public class ProductCategories : ObservableCollection<ProductCategory>
我的第一个想法是我可以通过使用 DataTrigger 来实现这一点;但是,这些似乎自 WinRT 以来不可用。我也可以为此使用某种消息通知,但我觉得这应该可以直接通过 XAML 绑定实现。
所以,我的问题是,当子类发生变化时,是否可以通知父类已发生变化。
【问题讨论】: