假设我有几个复选框,在ViewModel中有一个字符串列表。
public List Checks { get; set; }
我的目标是以这样的方式将我的复选框绑定到列表,当复选框1被选中时,“复选1”将被添加到列表中,当它被选中时,“复选1”将被删除,依此类推。
public class CheckBoxToListConverter : IValueConverter
{
List bound;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bound = value as List;
if (bound.Contains(parameter.ToString()))
return true;
else
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isChecked = (bool)value;
if (isChecked)
{
bound.Add(parameter.ToString());
return true;
}
else
{
bound.Remove(parameter.ToString());
return false;
}
}
}
然后我对我的复选框进行了以下绑定:
是什么导致了这个错误?我怎样才能以正确的方式完成这个任务?
最后
以上就是坚定宝贝最近收集整理的关于checkbox wpf 绑定数组_将WPF CheckBox.IsChecked绑定到列表的全部内容,更多相关checkbox内容请搜索靠谱客的其他文章。
发表评论 取消回复