WPF custom button using geometry from resource

Is there a way to use the PathGeometry collection as follows:

Path 1 F1 M 170.2578.178.837L 170.255.221.158C 170.255.228.917 164.172.230.777 156.745.225.286L 136.003.209.973C 128.572.204.488 128.572.195.512 136.003.190.023L 156.745.174.706C 164.17.17.179.217 170.25771 170.25771 170.25771

Path 2 F1 M 152,29,174,464L 134,314,187,734C 129,978,190,937 127,589,195,29 127,589,199,994C 127,589,204,7 129,978,209,057 134,342,212,26L 152,29,225,531C 150,333,229,378 145,412,229,52 139,678,229,29,211,611,211,611,211 .170.475 150.333.170.617 152.29.174.464 Z

and use them to create a custom button in the same way as you can make the circular button shown in this example? http://www.wpftutorial.net/Templates.html

An example involves redefining a control template and there seems to be a lot of work if I want to have many buttons in the form. But what if I want to load geometry points from a resource?

+6
c # wpf wpf-controls
source share
1 answer

No problem, this code goes to Resources.

<Geometry x:Key="geo"> M 152.29,174.464L 134.314,187.734C 129.978,190.937 127.589,195.29 127.589,199.994C 127.589,204.7 129.978,209.057 134.314,212.26L 152.29,225.531C 150.333,229.378 145.412,229.52 139.678,225.286L 118.935,209.973C 111.506,204.489 111.506,195.512 118.935,190.022L 139.678,174.708C 145.412,170.475 150.333,170.617 152.29,174.464 Z </Geometry> <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Path Data="{StaticResource geo}" Fill="HotPink" /> </ControlTemplate> </Setter.Value> </Setter> </Style> 
+10
source share

All Articles