开发者

WPF element property binding

I'v got two drop down lists. When selectedIndex for both of these is not -1 it should enable a button. How element property bin开发者_开发百科ding can be used here ?


You need to use a MultiBinding to bind the IsEnabled property of the Button to multiple SelectedIndex properties, and then you need an IMultiValueConverter to convert the numbers to a Boolean. Here is a great example: http://www.developingfor.net/wpf/multibinding-in-wpf.html


MultiBindings and MultiValueConverters work well, but my first advice to you would be to use M-V-VM. If you are using M-V-VM then you would simply tie the button enabling to a RelayCommand or to a property on your ViewModel such as IsActionAvaialable. I find that using M-V-VM results in me needing much fewer ValueConverters (just my 2 cents).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜