开发者

WPF correlating Multibindings and Converter's values[]

开发者 https://www.devze.com 2023-01-06 06:43 出处:网络
My XAML is as follows <Button.IsEnabled > <MultiBinding Converter=\"{StaticResource IsEnabledConverter}\" >

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

0

精彩评论

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