I want to have canvas in xaml where I place some icons. These icons are polygons like this:
<Polygon Points="0,0 20,50, 0,50 20,0" Fill="Red" Stretch="Uniform"/>
But I want to use the icon several times, so I want to define it in the resources and include it by reference in the canvas at a certain position, one way or another:
<Page.Resources>
<Polygon Key="icon1" Points="0,0 20,50, 0,50 20,0" Fill="Red" Stretch="Uniform"/>
<Polygon Key="icon2" Points="0,0 10,30, 10,60 20,0" Fill="Blue" Stretch="Uniform"/>
...
</Page.Resources>
<Canvas>
<Polygon Reference="icon1" X="0" Y="0"/>
<Polygon Reference="icon2" X="10" Y="10"/>
<Polygon Reference="icon1" X="20" Y="20"/>
...
</Canvas>
I found a possible solution at http://www.codeproject.com/KB/WPF/GraphicInXAMLAndWPF.aspx , where the polygons are stored in a graphic, but there seems to be a lot of overhead.
Does anyone have a better idea how to solve this?
source
share