2 回答
TA贡献2019条经验 获得超9个赞
如果没有完整的工作示例,就不容易给出完整的工作示例。
您可以使用其他方法解决您的问题。
你IndustryFilters不应该是ObservableCollection<IndustryFilter>这样的对象的实例:
public class IndustryFilters : INotifyPropertyChanged {
private _isAllChecked;
public IsAllChecked {
get {return _isAllChecked;}
set{
_isAllChecked = value;
foreach(var filter in Filters) {
filter.IsChecked = value;
}
PropertyChanged(...);
}
}
public ObservableCollection<IndustryFilter> Filters
{
get { return _industryFilters; }
set
{
_industryFilters = value;
PropertyChanged(this, new propertyChangedEventArgs("IndustryFilters"));
}
}
}
然后将IsCheckedof绑定<CheckBox x:Name="allIndustry">All</CheckBox> 到IsAllChecked属性。
然后,您必须找到一种方法将 ComboBox 的来源更改为 IndustryFilters.Filters。
希望这可以帮助。
TA贡献2041条经验 获得超4个赞
这是 State 过滤器的 ViewModel 属性定义 - 与我询问的 Industry 字段相同:
private ObservableCollection<StateFilter> _stateFilters;
public ObservableCollection<StateFilter> StateFilters
{
get { return _stateFilters; }
set
{
_stateFilters = value;
PropertyChanged(this, new PropertyChangedEventArgs("StateFilters"));
}
}
private bool _stateFilter;
public bool StateFilter
{
get { return _stateFilter; }
set
{
_stateFilter = value;
ObservableCollection<StateFilter> local = new ObservableCollection<StateFilter>();
foreach (var filter in StateFilters)
{
filter.IsChecked = _stateFilter;
local.Add(filter);
}
StateFilters = local;
PropertyChanged(this, new PropertyChangedEventArgs("StateFilter"));
}
}
这是 XAML 代码示例:
资源:
组合框:
<ComboBox Text="Select State" TextSearch.TextPath ="State" Name="state" IsEditable="True" IsReadOnly="True" >
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem >
<CheckBox Name="all" IsChecked="{Binding StateFilter}">All</CheckBox>
</ComboBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource stateSource}}"/>
</CompositeCollection>
</ComboBox.ItemsSource>
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Name="chkTask" IsChecked="{Binding IsChecked}" Content="{Binding State}" ></CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
- 2 回答
- 0 关注
- 544 浏览
添加回答
举报