I have a Grid and in it two Paths. When one style is applied on the Grid, the first Path should have some Data, and the second some other data. When the seconds style is applied, the first Path should have another Data, and the second Path should have another different Data. I wish to be able to set the Setter's target element name.
I tried the code below. I get two crosses instead of one triangle in the left and one cross in the right.
<Window x:Class="cs_wpf_test_2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:cs_wpf_test_2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style x:Key="styleWithPlusSign" TargetType="Path">
<Setter Property="Path.Data" Value="M 5,95 L 95,95 50,5 5,95"></Setter>
<Setter Property="Path.Data" Value="M 50,10 L 50,10 L 50,90 M 10,50 L 90,50"></Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Path Stroke="Blue"
Stretch="Fill"
x:Name="MyFirstPath"
Style="{StaticResource styleWithPlusSign}"
/>
<Path Grid.Column="1" Stroke="Black"
StrokeThickness="4"
Stretch="Uniform"
x:Name="MySecondPath"
Style="{StaticResource styleWithPlusSign}"/>
</Grid>
</Window>
I get the wished result using this inflexible code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Path Stroke="Blue"
Stretch="Fill"
x:Name="MyFirstPath"
Data="M 5,95 L 95,95 50,5 5,95"
/>
<Path Grid.Column="1" Stroke="Black"
StrokeThickness="4"
Stretch="Uniform"
x:Name="MySecondPath"
Data="M 50,10 L 50,10 L 50,90 M 10,50 L 90,50"/>
</Grid>
Screenshot:
If I try to use TargetName attribute of the Setters I get errors:
XDG0029 | The name "MyFirstPath" is not recognized.
XDG0029 | The name "MySecondPath" is not recognized.
Update
I am sorry for the unclarity. I want 2 styles, e.g. styleWithPlusSign and styleWithMinusSign.
- The
styleWithPlusSignshould set a triangle with a corner oriented up and a cross in the right. - The
styleWithMinusSignshould set a triangle with a corner oriented down and a minus sign (a line) in the right.


