tags:

views:

21

answers:

1

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="False" />
            </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.

+1  A: 
  1. The way you have done it is correct. I am not sure about the MultiTrigger, but this approach looks better anyway.
  2. If you want your Style to be based on the default textbox style, try the following:

<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">

Charlie
Thanks Charlie. I hadn't figured out how to make the style derive from the cascading default styles I already had. Your syntax fixed that. I do wish there were a better way to defined triggers, outside of a style though. Thanks!
BrettRobi