Path.Data styling works only on first instance of styled object Path.Data styling works only on first instance of styled object wpf wpf

Path.Data styling works only on first instance of styled object


Path.Fill is a DependencyProperty, while Path.Data isn't. Instead do:

<DataTemplate>    <Grid ...>        ...        <ContentPresenter Content="{StaticResource MyPath}"/>    </Grid></DataTemplate>

ContentPresenter.Content is a DependencyProperty so this should work:

<Path x:Key="MyPath" Margin="4" Style="{StaticResource ErrorIconPath}"       Stretch="Uniform" Width="26" Height="26" VerticalAlignment="Center"      RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"      UseLayoutRounding="False" HorizontalAlignment="Center"      Data="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z"/>


I am guessing that Geometry cannot be shared. Have you tried setting the x:Shared= "false" to:

<Style x:Key="ErrorIconPath" TargetType="Path">


I've experienced the same behavior in Silverlight and asked a similar question here on StackOverflow.com ( https://stackoverflow.com/q/13426198/1796930), but as I'm writing this, it's been 1 month and I've yet to get even a single answer.

However, as you mentioned in your first edit, I too was able to perform a workaround by creating a resource with my geometry data as a string and then binding the Data property of the Path objects to the string resource resource.

I also had to create two instances of the Path objects that were identical other than each one using a different resource (i.e. two different icons) and then binding the visibility of each to a property in my ViewModel to display the appropriate one.