WPF Styles and triggers

Whenever no selection is made from all checkboxes I want the user to see an orange border around the checkboxes. This is not a validation error, but a warning this is not the intended use. My style in XAML looks like this

<Style x:Key="WarningNoSelection" TargetType="{x:Type Border}">
   <Style.Triggers>
      <MultiDataTrigger>
         <MultiDataTrigger.Conditions>
            <Condition Binding="{Binding Path=AdminRole}"     Value="False" />
            <Condition Binding="{Binding Path=DataRole}"      Value="False" />
            <Condition Binding="{Binding Path=WebServer}"     Value="False" />
            <Condition Binding="{Binding Path=ResourceRole}"  Value="False" />
            <Condition Binding="{Binding Path=DataEntryRole}" Value="False" />
         </MultiDataTrigger.Conditions>
         <MultiDataTrigger.Setters>
            <Setter Property="BorderBrush" Value="Orange"/>
         </MultiDataTrigger.Setters>
      </MultiDataTrigger>
   </Style.Triggers>
</Style>

With the debugger described here. I found that the trigger was working but stil no orange border around my checkboxes. The problem was the BorderBrush property specified in the Border Tag. After removing that I got my orange border when no checkbox was checked.

<!--
<Border BorderBrush="Silver" Style="{StaticResource WarningNoSelection}" BorderThickness="1">
-->
<Border Style="{StaticResource WarningNoSelection}" BorderThickness="1">
    <StackPanel>
        <CheckBox Content="Admin"     IsChecked="{Binding Path=AdminRole}" />
        <CheckBox Content="Data"      IsChecked="{Binding Path=DataRole}" />
        <CheckBox Content="WebServer" IsChecked="{Binding Path=WebServer}" />
        <CheckBox Content="Resource"  IsChecked="{Binding Path=ResourceRole}" />
        <CheckBox Content="DataEntry" IsChecked="{Binding Path=DataEntryRole}" />
    </StackPanel>
</Border>

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s