views:

838

answers:

1

I'm having isues trying to access a PathGeometry resource in a Resource Library in a silverlight 3 app

Ive created a resource file called Geo.xaml

in my app.xaml i link to this file

<Application.Resources>
    <ResourceDictionary>
     <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="Components/Resources/Geo.xaml"/>
     </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

in my resource file i have the following line which has the geometry for a simple box

<PathGeometry x:Key="CloseCross">M0,0 L188,0 L188,161 L0,161 z</PathGeometry>

and then in my MainPage.xaml i have a path trying to use that resource

<Path Data="{StaticResource CloseCross}"  Stretch="Fill"  Margin="10,10,0,0" Width="100" Height="100" UseLayoutRounding="False" Fill="Red"/>

and in Blend 3 (RC) it all looks fine, the path takes on the geometry and displays fine, the problem is when i build it and view it in browser i get the following error

Attribute {StaticResource CloseCross} value is out of range. [Line: 8 Position: 14]

I discovered a semi work around but even that has issues, i can create a style for target type Path and use a setter to set the Data property of the Path

    <Style x:Key="PathStyle1" TargetType="Path">
 <Setter Property="Data" Value="M0,0 L188,0 L188,161 L0,161 z" />
</Style>

The problem with this is that when I apply that style, the geometry isnt displayed in blend, the path is there in the hierachy tree but is not visible on the canvas but when i build and view it in a browser, its all good...

can anyone help me understand why I cant seem to put path geometry in a resource file (or in fact anywhere)

+1  A: 

One problem is that in Silverlight you cannot store Paths within the ResourceDictionary. I would put the Path coordinates within a string resource, and then use http://StringToPathGeometry.codeplex.com to create the paths.

Saqib

related questions