I have a button with a custom ControlTemplate. During execution, I want to change the PathGeometry and Fill based on criteria the user selects.
In a ResourceDictionary I have two PathGeometry definitions:
<PathGeometry x:Key="Card" >
<PathFigure StartPoint="0,0" >
<LineSegment Point="0,50"/>
<LineSegment Point="100,50"/>
<LineSegment Point="100,20"/>
<LineSegment Point="80,0"/>
<LineSegment Point="0,0"/>
</PathFigure>
</PathGeometry>
and
<PathGeometry x:Key="Triangle" >
<PathFigure StartPoint="0,0" >
<LineSegment Point="50,50"/>
<LineSegment Point="100,0"/>
<LineSegment Point="0,0"/>
</PathFigure>
</PathGeometry>
In the same ResourceDictionary I have a Style defined:
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid" Background="White">
<Path Stroke="Black" StrokeThickness="2" Data="{DynamicResource Card}">
<Path.Style>
<Style TargetType="Path">
<Style.Triggers>
<DataTrigger
Binding="{Binding HatchType,
RelativeSource={RelativeSource FindAncestor, AncestorType=local:PullArrowConnector},
Mode=TwoWay}" Value="Withdrawal">
<Setter Property="Fill" Value="{DynamicResource HatchBrush}" />
</DataTrigger>
<DataTrigger
Binding="{Binding HatchType,
RelativeSource={RelativeSource FindAncestor, AncestorType=local:PullArrowConnector},
Mode=TwoWay}" Value="Production">
<Setter Property="Fill" Value="Transparent" />
</DataTrigger>
<DataTrigger
Binding="{Binding HatchType,
RelativeSource={RelativeSource FindAncestor, AncestorType=local:PullArrowConnector},
Mode=TwoWay}" Value="Signal">
<Setter Property="Path.Data" Value="{DynamicResource Triangle}" />
<Setter Property="Fill" Value="Transparent" />
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Using a DataTrigger, I'm able to dynamically control the Fill property, but not the Data property. I understand that Data is not a property of Path.Style, but its not clear to me how I can dynamically change the PathGeometry at runtime. The third DataTrigger shown above where I try to set the Path.Data property doesn't work.