I am trying to reuse shape data to dynamically create new shapes in code. Basically I want to do this http://stackoverflow.com/questions/839843/reuse-path-object-in-xaml but in code. Here is the situation:
Path path = new Path();
path.Style = (System.Windows.Style)this.Resources["PathStyle"];
Path path2 = new Path();
path2.Style = (System.Windows.Style)this.Resources["PathStyle"];
But i get an ArgumentException on the fourth line saying "Value does not fall within the expected range"
The code is in the MainControl of a SL 3 application. The XAML code for the resource is
<UserControl.Resources>
<Style x:Key="PathStyle" TargetType="Path">
<Setter Property="Data" Value="M63,171 L138,117 L168,189 L99,219"/>
<Setter Property="Fill" Value="#FFF07E7E"/>
<Setter Property="Height" Value="103"/>
<Setter Property="Width" Value="106"/>
<Setter Property="Stroke" Value="#FF000000"/>
<Setter Property="Stretch" Value="Fill"/>
</Style>
</UserControl.Resources>
Any ideas?