I have many PathGeometry instances that draw a variety of graphics for different buttons. So I have created a button type for showing a Path which then updates the Path.Stroke depending on the button state. So show it grayed when disabled and different colours when the mouse is over. Standard stuff...
<Style x:Key="BasePathButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="Border"
<Path x:Name="Path" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Path" Property="Stroke" Value="Gray"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Path" Property="Stroke" Value="Green"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Path" Property="Stroke" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But obviously I need different Path.Data for each button instance. So I create a BasedOn style for setting the Path.Data like this...
<Style x:Key="NLB" TargetType="{x:Type Button}" BasedOn="{StaticResource BasePathButton}">
<Setter TargetName="Path" Property="Data" Value="{StaticResource LeftPathGeometry}"/>
</Style>
...but this fails with an error that TargetName="Path" cannot be found. Any ideas how to fix this? Or maybe a better way to create a button that has a Path which is parameterized with the geometry to use?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…