WPF: Cancel a user selection in a databound ListBox?

前端 未结 8 773
独厮守ぢ
独厮守ぢ 2020-12-05 01:02

How do I cancel a user selection in a databound WPF ListBox? The source property is set correctly, but the ListBox selection is out of sync.

I have an MVVM app that

8条回答
  •  渐次进展
    2020-12-05 01:27

    Bind ListBox's property: IsEnabled="{Binding Path=Valid, Mode=OneWay}" where Valid is the view-model property with the validation algoritm. Other solutions look too far-fetched in my eyes.

    When the disabled appearance is not allowed, a style could help out, but probably the disabled style is ok because changing the selection is not allowed.

    Maybe in .NET version 4.5 INotifyDataErrorInfo helps, I dont'know.

提交回复
热议问题