如何在更新项目时发出observableCollection通知,而不仅仅是在添加或删除项目时?

Ric*_*ães 2 wpf events itemscontrol observablecollection

我有一个ItemsControl对象绑定到ObservableCollection.

这是我的ItemsControl:

<ItemsControl x:Name="AvailableProjects" ItemsSource="{Binding ProjectsList}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <CheckBox x:Name="IsProjectSelected" IsChecked="{Binding IsProjectSelected}" />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
Run Code Online (Sandbox Code Playgroud)

这是我的ObservableCollection:

public ObservableCollection<ProjectInfo> ProjectsList  { get; set; }
Run Code Online (Sandbox Code Playgroud)

我希望当用户按下checkBox时,observableCollection的"CollectionChanged"事件被触发但它不起作用.我注意到复选框项正在处理事件,似乎ObservableCollection没有注意到.有人可以帮我这个吗?提前致谢!

小智 6

ObservableCollection目的是通知更改集合,通知修改您必须INotifyPropertyChanged在集合中包含的对象中实现的对象.

  • 嗨马蒂亚!你是对的!太感谢了。正如在 CodeProject 中发现的一个很好的例子:http://www.codeproject.com/Tips/694370/How-to-Listen-to-Property-Chang (2认同)