问题描述
有没有办法使用的PathGeometry的集合这样的一种方式:
Is there a way to use a collection of PathGeometry like these:
路径1
F1中号170.255,178.837L 170.255,221.158C 170.255,228.917 164.174,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.174,169.217 170.255,171.079 170.255,178.837ž
Path 1F1 M 170.255,178.837L 170.255,221.158C 170.255,228.917 164.174,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.174,169.217 170.255,171.079 170.255,178.837 Z
路径2
F1中号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ž
Path 2F1 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
和用它们来使自定义你可以在这个例子中所示的圆形按钮,以同样的方式按钮?
and use them to make a custom button in the same way you can make a circular button shown in this example?http://www.wpftutorial.net/Templates.html
例子中包括重写控件模板,似乎很多工作,如果我想有许多自定义形状的按钮。而如果我想从资源加载几何点?
The example involves overriding the control template and it seems a lot of work if I want to have many custom-shaped buttons. And what if I want to load the geometry points from the resource?
推荐答案
没有问题,这个代码进入资源。
No problems, this code goes into 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>
这篇关于利用资源几何WPF自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!