2013-01-05 85 views
4

我有一个ControlTemplate,是作为一个给定的控制AdornerLayer“泡沫”弹出。WPF - 路径几何...有没有办法绑定数据属性?

它工作正常,但我需要能够计算出它应该显示(中/下)。

相反的:

<Path Stroke="Black" Fill="Black" Data="M 15 20 L 15 0 33 20" Margin="0 1 0 0"/> 

我要找(这显然是行不通的,但它说明了什么,我试图完成:

<Path Stroke="Black" Fill="Black" Data="M {TemplateBinding Left} 20 L 15 0 33 20"/> 

可以这样用ValueConverter完成?由于某种原因,我无法想象解决方案,我也愿意替代。

感谢您的阅读,如果我可以提供更多信息,请直接询问

+1

我可能在这里找到答案...但想看看是否有其他人有输入? http://stackoverflow.com/questions/4631231/path-drawing-and-data-binding – tronious

+0

这可能有助于https://stackoverflow.com/a/46349999/1468295 –

回答

7

如果你想,你可以使用一个字符串转换成路径数据的值转换器,你可能想尝试的universal value converter我写了一段时间回来。

另外,绑定到一个单一的财产,你将不得不将各种几何对象到您的XAML,而不是使用字符串速记扩展几何体。例如...

<Path Stroke="Black" StrokeThickness="1"> 
    <Path.Data> 
    <PathGeometry> 
     <PathGeometry.Figures> 
     <PathFigureCollection> 
      <PathFigure IsClosed="True" StartPoint="10,100"> 
      <PathFigure.Segments> 
       <PathSegmentCollection> 
       <LineSegment Point="{Binding MyPropertyPath}" /> 
       <LineSegment Point="100,50" /> 
       </PathSegmentCollection> 
      </PathFigure.Segments> 
      </PathFigure> 
     </PathFigureCollection> 
     </PathGeometry.Figures> 
    </PathGeometry> 
    </Path.Data> 
</Path> 
+0

非常有帮助...谢谢 – tronious

相关问题