如何将一个XAML代码(代表一组形状)更改为PATH提供的单个数字?
假设我们有XAML代码,例如:
<Ellipse Fill="#FF0A0A0E" HorizontalAlignment="Left" Margin="192,184,0,0"
Stroke="Black" Width="8" Height="8" VerticalAlignment="Top"/>
<Rectangle Fill="Black" HorizontalAlignment="Left" Margin="152,187.5,0,0"
Stroke="Black" Width="89.5" Height="1" VerticalAlignment="Top"/>
并需要将其转换为单个路径对象吗?
我尝试使用Blend 4,它允许您将形状转换为路径,但上面的代码转换为:
<Path Data="M7.5,4 C7.5,5.9329966 5.9329966,7.5 4,7.5 C2.0670034,7.5 0.5,5.9329966 0.5,4 C0.5,2.0670034 2.0670034,0.5 4,0.5 C5.9329966,0.5 7.5,2.0670034 7.5,4 z"
Fill="#FF0A0A0E" HorizontalAlignment="Left" Height="8" Margin="192,184,0,0"
Stretch="Fill" Stroke="Black" VerticalAlignment="Top" Width="8"/>
<Path Data="M0.5,0.5 L89,0.5 z" Fill="Black" HorizontalAlignment="Left" Height="1"
Margin="152,187.5,0,0" Stretch="Fill" Stroke="Black" VerticalAlignment="Top"
Width="89.5" />
我问这个问题的原因是因为我只能定义一个路径。如我错了请纠正我。如果是这样,那么如何在一种风格中嵌入2条或更多条路径?
答案 0 :(得分:2)
您可以使用Expression Blend 4将两个形状合并为一个Path
。
要做到这一点,请按住ctrl或shift
选择它们
之后,选择对象 - &gt;合并 - &gt;团结
在你的情况下,它会输出这个
<Path Data="M44,0.5 C45.932995,0.50000024 47.5,2.0670036 47.5,4.0000002 L89,4.0000002 89,4.0100003 47.499496,4.0100003 47.48193,4.3578544 C47.302696,6.122751 45.812183,7.5000002 44,7.5000002 42.187817,7.5000002 40.697304,6.122751 40.51807,4.3578544 L40.500504,4.0100003 0.5,4.0100003 0.5,4.0000002 40.5,4.0000002 C40.5,2.0670036 42.067005,0.50000024 44,0.5 z"
Fill="Black"
HorizontalAlignment="Left"
Height="8"
Margin="152,184,0,0"
Stretch="Fill"
Stroke="Black"
VerticalAlignment="Top"
Width="89.5"/>
请注意,如果矩形Height
正好为1,则会出现此错误。然后它就会消失。要解决此问题,只需将Height
设置为类似1.00001
<Rectangle Fill="Black" HorizontalAlignment="Left" Margin="152,187.5,0,0"
Stroke="Black" Width="89.5" Height="1.00001" VerticalAlignment="Top"/>
答案 1 :(得分:0)
可以使用一个数据字段执行多个单独的路径。例如:
<Path Data="M0,0 L 10,10 L 20, 10 L 20,0 z M 100,5 L 110,15 L 120,15 L 120,5 z"
Stroke="Black" Fill="Red" />
但是,假设您希望在两个部分中都使用相同的Fill
,Stroke
等,这在您的示例中并非如此。