[英]CollectionViewSource Binding not updating when removing or adding item
I'm having trouble with my combobox updating when binding to a list. 绑定到列表时我的组合框更新有问题。 All other controls properly update when I make changes.
我进行更改时,所有其他控件都会正确更新。 I'm attempting to remove an item from the drop down list from a button.
我正在尝试从按钮中删除下拉列表中的项目。
<CollectionViewSource Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=statusList}" x:Key="statusList"/>
. 。
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Tag="{Binding ID}" Content="{Binding Name}" Foreground="White" Margin="10,0,0,0" Checked="Filter_Checked" Unchecked="Filter_Checked" IsChecked="{Binding ElementName=Filter21Days, Path=IsChecked, Mode=OneWay}"></CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem Content="Filter" Visibility="Collapsed" IsEnabled="False"/>
<ComboBoxItem>
<CheckBox x:Name="ViewAllFilter" Content="View All" Foreground="White" Margin="10,0,0,0" Checked="Filter_Checked" Unchecked="Filter_Checked" IsChecked="False"></CheckBox>
</ComboBoxItem>
<ComboBoxItem>
<CheckBox x:Name="Filter21Days" Content="Last 21 Days" Foreground="White" Margin="10,0,0,0" Checked="Filter_Checked" Unchecked="Filter_Checked" ></CheckBox>
</ComboBoxItem>
<ComboBoxItem>
<CheckBox x:Name="FilterBydate" Content="By Date" Foreground="White" Margin="10,0,0,0" Checked="Filter_Checked" Unchecked="Filter_Checked" Visibility="Collapsed"></CheckBox>
</ComboBoxItem>
<ComboBoxItem>
<Separator Background="White" Width="110" Height="1"></Separator>
</ComboBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource statusList}}"/>
</CompositeCollection>
</ComboBox.ItemsSource>
. 。
ObservableCollection<Status> _statusList = new ObservableCollection<Status>();
public ObservableCollection<Status> statusList
{
get { return _statusList; }
set { _statusList = value; }
}
The issue was with the way I was manipulating the statusList. 问题在于我操纵statusList的方式。 I had statusList = another list, which didn't trigger the property changed.
我有statusList =另一个列表,它没有触发属性更改。 Worked around it with a for loop like below.
使用下面的for循环来解决它。
statusList.Clear();
for (int i = 0; i < statusWindow.statusList.Count; i++)
{
statusList.Add(statusWindow.statusList[i]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.