My XAML is as follows
<Button.IsEnabled >
<MultiBinding Converter="{StaticResource IsEnabledConverter}" >
&开发者_StackOverflow中文版lt;Binding Path="aaa"/>
<Binding Path="bbb"/>
<Binding Path="ccc"/>
<Binding Path="ddd"/>
<Binding Path="eee"/>
<Binding Path="fff"/>
<Binding Path="ggg"/>
<Binding Path="hhh"/>
<Binding Path="iii"/>
<Binding Path="jjj"/>
</MultiBinding>
</Button.IsEnabled>
Now in my Convert function i get 10 values and its a headache to keep the binding sequence and index number of values collection in sync. There has to be a better way to connect these two. How to?
Instead of using a converter at all, bind it to a property in your viewmodel that does the conversion
public bool IsEnabled
{
get
{
return (aaa || bbb || ccc || ddd || eee)
&& fff && ggg && hhh && iii && jjj;
}
}
<Button IsEnabled="{Binding Path=IsEnabled}" />
Although having View-Model would be a better way, for those who are not using view-model, or cannot modify existing view-model, check out my post : http://technologyandme.blogspot.com/2010/07/wpf-converter-values.html
精彩评论