-2

if((a&&(b||c||d)) || (e&&(f||g||h)))

then set button Isenabled property true

I want to implement this feature for a button in using style trigger in WPF.

Thanks in advance.

  • There are multiple ways to handle this kind of thing as all of the generous answers say, but the best advice I can give you is that this is the exact kind of logic you want to keep out of your form, and handle in your ViewModel (MVVM approach). Then your binding will be very simple. – Liz Aug 30 '13 at 15:52

3 Answers3

1

Simplest way will be to bind all these using Mutlivalueconverter to IsEnable property in style and put this logic in converter's Convert method:

<Style TargetType={x:Type Button}>
<Setter Property="IsEnabled">
                        <Setter.Value>
                            <MultiBinding Converter="{StaticResource MyConverter}">
                            <Binding Path="a"/>
                            <Binding Path="b"/>
                            <Binding Path="c"/>
                            <Binding Path="d"/>
                            <Binding Path="e"/>
                            <Binding Path="f"/>
                            <Binding Path="g"/>
                            <Binding Path="h"/>
                            </MultiBinding>
                        </Setter.Value>
                    </Setter>
</Style>

Here MyConverter is the Multivalueconverter.

Thanks

Nitin
  • 18,344
  • 2
  • 36
  • 53
1

There is no || in a MultiDataTrigger. You have to use multiple triggers instead. Take your expression and extract all subexpressions without || when the button shall be enabled:

  • a && b
  • a && c
  • a && d
  • e && f
  • e && g
  • e && h

Now for each of them build a MultiDataTrigger in your Style which sets the Enabled property of the button to true. That's it.

Torben Schramme
  • 2,104
  • 1
  • 16
  • 28
0

As others have mentioned, there is no built-in support for arbitrary Boolean expressions in WPF.

If you are willing to add third-party software, however, PyBinding allows you to use Python expressions in WPF binding:

<Button IsEnabled="{p:PyBinding $[.a] and ($[.b] or $[.c] or $[.d]) ... }"/>
Heinzi
  • 167,459
  • 57
  • 363
  • 519