2013-01-05 66 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

相關問題