Note to self: Turning a Path into a Resource in XAML

Wednesday, January 13, 2010 / Posted by Luke Puplett /

Simple post mainly as a reminder to myself explaining how to make a complex path reusable because I keep forgetting this easy thing.

This goes in the asset resource dictionary.

<PathGeometry x:Key="ArrowHeadPath" Figures="M140.00002,39.999641 C134.47716,39.999641 129.47714,42.23822 125.85786,45.857513 L124.94602,46.962662 51.908844,119.99984 124.94678,193.03778 125.85786,194.14201 C129.47714,197.76131 134.47716,199.99988 140.00002,199.99988 151.04572,199.99988 160.00005,191.04556 160.00005,179.99985 160.00005,174.47699 157.76146,169.47699 154.14217,165.8577 L153.43225,165.27196 153.55394,165.14679 108.407,119.99986 154.20343,74.203423 154.14198,74.141975 154.14217,74.14183 C157.76146,70.522537 160.00005,65.52253 160.00005,59.999672 160.00005,48.95396 151.04572,39.999641 140.00002,39.999641 z M120,0.5 C185.99803,0.5 239.5,54.001972 239.5,120 239.5,185.99803 185.99803,239.5 120,239.5 54.001972,239.5 0.5,185.99803 0.5,120 0.5,54.001972 54.001972,0.5 120,0.5 z" />

Then this is how to use it (StaticResource probably better, transforms just for demo):

<Path Data="{DynamicResource ArrowHeadPath}" RenderTransformOrigin="0.7,0.5" MouseLeftButtonDown="ActivateWindowDrag" >
<Path.Fill>
<RadialGradientBrush GradientOrigin="0.495,0.55">
<GradientStop Color="#FFE2E2E2" Offset="0"/>
<GradientStop Color="#CC0F0316" Offset="0.3"/>
</RadialGradientBrush>
</Path.Fill>
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="3.6" ScaleY="3.6"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="8"/>
<TranslateTransform X="5" Y="-160"/>
</TransformGroup>
</Path.RenderTransform>
</Path>

Labels: ,

0 comments:

Post a Comment