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>
Unknown's avatar

About erictummers

Working in a DevOps team is the best thing that happened to me. 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 comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.