WPF multitrigger referencing 2 other controls
I have two CheckBoxes and a TextBox. I want to TextBox to have IsEnabled=False if both CheckBoxes have IsChecked=False. Can I do this with a MultiTrigger? I keep getting errors trying to use the Source property.
I have it working with MultiDataTriggers as you can see below. But have two questions.
1) Is this my only choice? Can I do it with a MultiTrigger?
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=uxDmm , Path=IsChecked}"
Value="False" />
<Condition Binding="{Binding ElementName=uxGpm , Path=IsChecked}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled"
Value="Fal开发者_JS百科se" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
2) Can I do this outside of the tag? I'm not really sure where Triggers can be applied, most samples do it within Style or DataTemplates, but defining it within a Style is messing up my default look and feel for the TextBox.
- The way you have done it is correct. I am not sure about the
MultiTrigger
, but this approach looks better anyway. - If you want your
Style
to be based on the default textbox style, try the following:
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
精彩评论