質問

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.

役に立ちましたか?

解決

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

他のヒント

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]) ... }"/>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top