我有一个带有布尔列的网格。我正在尝试与另一个复选框控件相关联,因此当我选中此复选框时,我的窗口会显示网格中的元素,其中布尔列为 true(选中)。
这是我的 IsChecked 财产
private bool _isChecked;
public bool IsChecked
{
set
{
_isChecked = value;
InitializeMappedElements();
}
get { return _isChecked; }
}
这是一种仅从网格中选择映射元素的方法 public ObservableCollection MappedList { get { return _mappedList; } 设置 { _mappedList = 值;} }
private ObservableCollection<MessageFieldViewModel> _mappedList = new ObservableCollection<MessageFieldViewModel>();
private void InitializeMappedElements()
{
if (_isChecked)
{
var transactionRuleList =
MessageFieldVModel.GetAllMessageField().Where(ame => ame.IsMapped == _isChecked);
_mappedList = new ObservableCollection<MessageFieldViewModel>(transactionRuleList);
messageFields = _mappedList;
NotifyPropertyChanged("MessageFields");
}
}
在选择时与网格关联
public ObservableCollection<MessageFieldViewModel> MessageFields
{
set
{
if (_isChecked)
{
InitializeMappedElements();
}
NotifyPropertyChanged("MessageField");
}
get { return messageFields; }
}
XAML
<CheckBox Foreground="WhiteSmoke" Content="Display only Mapped Fields" HorizontalAlignment="Center"
Margin="198,35,473,74" FontFamily="Trebuchet MS" FontWeight="Bold" Grid.Column="1"
IsChecked="{Binding Path= IsChecked,Mode=TwoWay}">
</CheckBox>
当我选择什么都没有显示。为什么这不起作用?谢谢你。