gpt4 book ai didi

.net - WPF 列表框 + 绑定(bind) + IDataErrorInfo =?

转载 作者:行者123 更新时间:2023-12-02 05:19:36 26 4
gpt4 key购买 nike

我有一个 WPF MVVM 应用程序。在 View 中,我有一个多选 ListBox .在 ViewModel 中,我有一个列表中所选项目的属性。

使用类似于 this 答案中的技术问题我可以将我的属性绑定(bind)到 ListBox .

但我也想通过 IDataErrorInfo 进行数据验证.我要做的就是检查用户是否至少选择了列表中的一项。添加 ValidatesOnDataErrors=True绑定(bind)不起作用。

有没有办法让多选列表框与 IDataErrorInfo 数据绑定(bind)?

最佳答案

如果您正在使用将 ViewModel 的列表与 ListBox 的选定项目绑定(bind)的行为,请在添加/删除项目后手动更新绑定(bind):

var binding = BindingOperations.GetBindingExpression(this, SelectedItemsListBoxBehavior.SelectedItemsProperty);
if (binding != null)binding.UpdateSource();

关于.net - WPF 列表框 + 绑定(bind) + IDataErrorInfo =?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1226605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com