Friday, 25 May 2012

WPF Property Value Precedence and Style Setter

My DataTrigger / Setter was not changing the StrokeThickness property because it was exclicitly set in the Rectange tag. Property Value Precedence meant that the Setter was being overriden by the explicit property value. Moving the StrokeThickness default value into its own Setter fixed my problem.

<Rectangle
            Stroke="Black">
   <Rectangle.Style>
      <Style TargetType="{x:Type Rectangle}">
         <Setter Property="StrokeThickness"
                  Value="1" />
         <Style.Triggers>
            <DataTrigger Binding="{Binding Path=Selected}"
                           Value="True">
               <Setter Property="StrokeThickness"
                        Value="2" />
            </DataTrigger>
         </Style.Triggers>
      </Style>
   </Rectangle.Style>
</Rectangle>

No comments: