wpf – 在XAML中从Shape转换为Path

如何将一个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" />

我问这个问题的原因是因为我只能定义一个Path.如我错了请纠正我.如果是这样,那么如何在一种风格中嵌入2条或更多条路径呢?

最佳答案 您可以使用Expression Blend 4将两个形状组合成一个路径.

要做到这一点,请按住ctrl或shift选择它们

之后,选择对象 – >合并 – >团结

在你的情况下,它会输出这个

<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"/>

请注意,如果矩形高度正好为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"/>
点赞