I want to bind the IsEnabled
property (of a ribbon button) to a lists size. So when lists size is > 0 then IsEnabled
is set to true
else (if 0) it's set to false. How do you do开发者_如何学C that?
Bind to the lists Count
property and create your own ValueConverter
to convert from an int
to a bool
(in your case returning true
if the int is larger than 0 and false
otherwise). Note that your list would need to raise a PropertyChanged
event when the count changes - ObservableCollection
does that for example.
Either do it with a DataTrigger that binds to the Count property of the list and sets IsEnabled to false if it is zero, or use a ValueConverter.
However take care, that a List<T>
does not implement INotifyPropertyChanged
, which informs about changes of the Count property. An ObservableCollection<T>
will do.
精彩评论