3

I am trying to re-use a XAML <Path /> that I have made for an icon in my Windows 8 Store App, however when I attempt to re-use them more than once, it never displays?

For example, both the initial instances are fine and my Tick/Cross path renders with this XAML code:

<Path x:Name="TickGlyph" Style="{StaticResource TickGlyph}" Fill="#FF008500"
  Grid.Column="1" Width="48" Height="48" Margin="24,0,4,0" />
<Path x:Name="CrossGlyph" Style="{StaticResource CrossGlyph}" Fill="#FF850000"
  Grid.Column="1" Width="48" Height="48" Margin="24,0,4,0" />

As soon as I repeat that code with names like TickGlyph1 etc, my subsequent paths are simply blank, could anybody explain what's going on here, or is this some weird limitation with XAML for Windows Store apps?

My underlying Styles are as follows:

<Style x:Key="TickGlyph" TargetType="Path">
  <Setter Property="Data" Value="F1 M 45.12,5.49L 21.255,40.8L 20.4525,40.8L 0,23.2875L 5.775,15.7875L 19.2525,27.3L 37.695,-1.90735e-006L 45.12,5.49 Z "/>
  <Setter Property="Stretch" Value="Fill"></Setter>
</Style>
<Style x:Key="CrossGlyph" TargetType="Path">
  <Setter Property="Data" Value="F1 M 0,32.505L 13.4025,19.1025L 0,5.69249L 5.67,-7.62939e-006L 19.08,13.41L 32.505,-7.62939e-006L 38.205,5.67L 24.7725,19.1025L 38.205,32.535L 32.505,38.205L 19.08,24.795L 5.67,38.205L 0,32.505 Z "/>
  <Setter Property="Stretch" Value="Fill"></Setter>
</Style>


Update 2012-10-20: The strange thing is, if I replace Style="{StaticResource TickGlyph}" for Data="F1 M 45.12,5.49L 21.255,40.8L 20.4525,40.8L 0,23.2875L 5.775,15.7875L 19.2525,27.3L 37.695,-1.90735e-006L 45.12,5.49 Z " all my paths load ok, why won't the Style attribute honour? :(
GONeale
  • 26,302
  • 21
  • 106
  • 149
  • Did you find a solution to this problem? I am facing a similar issue – devson Jan 23 '13 at 12:09
  • No sorry devson, for now I duplicated each ``. I don't particularly like the idea of making a new .xaml file for each path as per Martin's solution, but it may work if you want to give it a try. – GONeale Jan 24 '13 at 00:43
  • I had the same problem and ended up wrapping the Path in a ContentControl like suggested here: http://stackoverflow.com/a/8838443/25182 – Nathan Jul 19 '13 at 18:24

1 Answers1

1

Not sure, if it's the best solution, but I have used this approach few days ago:

Define your own object that inherits from Path using XAML

<Path x:Class="MyProject.MyPath"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Data="F1M1568.35,1934.42L1551.46,1917.44 1551.46,1925.43C1517.67,1925.43 1515.02,1945.4 1515.02,
        1949.39 1522.31,1933.42 1551.46,1941.4 1551.46,1941.4L1551.46,1949.39 1568.35,1934.42z"
    Stretch="Uniform" Width="26" Height="26" UseLayoutRounding="False" RenderTransformOrigin="0.5,0.5">
</Path>

use default codebehind

public partial class MyPath 
{
    public MyPath()
    {
        InitializeComponent();
    }
}

and then instantiate it where you want.

Martin Suchan
  • 10,600
  • 3
  • 36
  • 66
  • That's an interesting approach, did you resort to this because you also had trouble doing it the way I did Martin? – GONeale Oct 14 '12 at 11:54
  • I was trying to solve another issue in WP7 app - if you use Icon somewhere, you need to have one for black and one for white theme. I rather wanted to use one object with color defined using Style - this worked. – Martin Suchan Oct 14 '12 at 14:09
  • Ah okay. Actually for a WP7 app I did, mine automatically changed accordingly depending on color theme on phone? (For app bar that is) – GONeale Oct 15 '12 at 03:44
  • AppBar buttons are changing the color automatically, but you have to provide right image/element for other visual elements or buttons. – Martin Suchan Oct 16 '12 at 14:09