I would like to enable button only when all specified ComboBoxes have values. However, as soon as I add a second condition, button is enabled from the start
Here is my code
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=SensorPartNumberComboBox, Path=SelectedValue}" Value="{x:Null}"/>
<Condition Binding="{Binding ElementName=SensorTypeComboBox, Path=SelectedValue}" Value="{x:Null}"/>
<Condition Binding="{Binding ElementName=SensorBrandNameComboBox, Path=SelectedValue}" Value="{x:Null}"/>
<Condition Binding="{Binding ElementName=DimmingProtocolComboBox, Path=SelectedValue}" Value="{x:Null}"/>
<Condition Binding="{Binding ElementName=Wired_WirelessComboBox, Path=SelectedValue}" Value="{x:Null}"/>
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False"/>
</MultiDataTrigger>
</Style.Triggers>
I would appreciate any help!
MultiDataTriggerrequires all of the conditions to be true for it to take effect. I.e. it's equivalent to a logical AND.In your example, if any value is non-null, the trigger won't take effect and the button will remain enabled.
For a logical OR, instead of using
MultiDataTrigger, just use multipleDataTrigger. If any condition of any trigger is true, then that trigger will take effect, with precedence over the default setter for the property in the style.For example:
Alternatively, you might consider putting the logic in your view model, with a single
boolproperty you bind to, and which is set according to the boundSelectedValueproperties for the variousComboBoxcontrols.Yet another alternative would be to use
MultiBindingto bind the five view model properties that are bound to theComboBox.SelectedValueproperties, with aIMultiValueConverterthat implements the logic.Of course, these last two options work only if you've got a proper view model with binding set up in the first place (something I strongly encourage, if you haven't already).