我想将相同的属性应用于我的所有多边形:
Polygon polygon = new Polygon();
polygon.StrokeThickness = 2;
polygon.Stroke = Brushes.Black;
polygon.Fill = (Brush)FindResource("HatchBrush");
polygon.ToolTip = (Image)FindResource("GapImg");
我该怎么做?
最佳答案
您可以使用Style
property .
在资源字典中定义您的样式:
<Style x:Key="PolygonStyle" TargetType="Polygon">
<Setter Property="Stroke" Value="Black" />
<Setter Property="StrokeThickness" Value="2" />
<Setter Property="Fill" Value="{StaticResource HatchBrush}" />
<Setter Property="ToolTip" Value="{StaticResource GapImg}" />
</Style>
然后使用 FindResource对于每个多边形
:
Polygon polygon = new Polygon()
{
Style = FindResource("PolygonStyle") as Style,
};
如果您需要将样式应用于所有多边形,只需删除x:Key
,您甚至不需要在运行时查找资源 。
关于c# - 将相同的属性应用于我的所有多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051035/