Question

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.

Était-ce utile?

La solution

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

Autres conseils

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.

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]) ... }"/>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top