wpf - What is the way to reuse a XAML DrawingImage changing only the PathGeometry LineSegments? -


i have 3 buttons in wpf application want display image of triangle. i'm not using shape class because it's heavyweight needs, i'm using drawingimage instead. here markup image (i post clean-looking image can't yet i'm new):

<image>     <image.source>         <drawingimage>             <drawingimage.drawing>                 <geometrydrawing brush="lawngreen">                     <geometrydrawing.pen>                         <pen brush="black" thickness="1" />                     </geometrydrawing.pen>                     <geometrydrawing.geometry>                         <pathgeometry>                             <pathfigure   isclosed="true">                                 <linesegment point="-10, 20" />                                 <linesegment point="30, 20" />                             </pathfigure>                         </pathgeometry>                     </geometrydrawing.geometry>                 </geometrydrawing>             </drawingimage.drawing>         </drawingimage>     </image.source> </image> 

this image first button - scalene triangle peak on left. other 2 buttons' xaml identical - change being line segment points different peak in middle , right of axes, respectively.

how can make 1 declaration image.source->drawingimage above without specific line segment coordinates, , like

<button>       <image source="mygenericdrawingimage">           <!--*fill in pathgeometry>pathfigure> linesegment coordinates each button-->       </image>   </button> 

this cleaner having dump blocks of identical code next each other.

i know old, here's solution used. set path geometry resource, , reference style (great re-use). make arrow point sideways, re-use same icon , rotate 90 degrees.

enter image description here

<page   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   xmlns:sys="clr-namespace:system;assembly=mscorlib">  <page.resources>   <sys:string x:key="icon_arrowdown">           f1 m 4.439,0.000 l 2.219,3.112 l 0.000,0.000 l 4.439,0.000 z       </sys:string> </page.resources>  <stackpanel>   <button>    <path data="{staticresource  icon_arrowdown}" fill="red" /> </button>  <button>     <path data="{staticresource icon_arrowdown}" fill="red" />         <path.rendertransform>             <compositetransform rotation="-90"/>         </path.rendertransform>     </path> </button>  </stackpanel> </page> 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -