gpt4 book ai didi

c# - 在 XAML 中重用路径对象

转载 作者:可可西里 更新时间:2023-11-01 07:49:53 27 4
gpt4 key购买 nike

我有一条路径(一个星形图):

<Path x:Name="NiceStar" StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 126.578613,11.297852 L 162.373535,83.825684 L 242.412598,95.456055 L 184.495605,151.911133 L 198.167480,231.626953 L 126.578613,193.990234 L 54.988770,231.626953 L 68.661621,151.911133 L 10.744629,95.456055 L 90.783691,83.825684 L 126.578613,11.297852 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="390.395508,448.130371" Center="390.395508,448.130371" RadiusX="113.034821" RadiusY="113.034821">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-263.816895,569.592773" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ff00ff00"/>
<GradientStop Offset="1" Color="#ff006736"/>
</RadialGradientBrush>
</Path.Fill>
</Path>

现在我想多次复制这条路径(仅指“NiceStar”)。我可以在纯 XAML 中执行此操作吗?

通过这样做,我可以使用它一次:

<Decorator Child="{StaticResource star}" />

但是,我无法复制这一行。我的编译器说:

Specified element is already the logical child of another element. Disconnect it first.

最佳答案

创建样式。

<Style x:Key="NiceStarPath" TargetType="{x:Type Path}">
<Setter Property="StrokeThickness" Value="10"/>
<Setter Property="Stroke" Value="#FF000000"/>
<Setter Property="StrokeMiterLimit" Value="1"/>
<Setter Property="Data" Value="F1 M 126.578613,11.297852 L 162.373535,83.825684 L 242.412598,95.456055 L 184.495605,151.911133 L 198.167480,231.626953 L 126.578613,193.990234 L 54.988770,231.626953 L 68.661621,151.911133 L 10.744629,95.456055 L 90.783691,83.825684 L 126.578613,11.297852 Z"/>
<Setter Property="Fill">
<Setter.Value>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="390.395508,448.130371" Center="390.395508,448.130371" RadiusX="113.034821" RadiusY="113.034821">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-263.816895,569.592773" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ff00ff00"/>
<GradientStop Offset="1" Color="#ff006736"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Style>

...

<Path Style="{StaticResource NiceStarPath}"/>

关于c# - 在 XAML 中重用路径对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/839843/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com