2013-05-14 150 views
2

我有一個名爲X類型的Item屬性的控制, Item有一個名爲Y類型的Tag屬性,和Tag具有其他的一些性質(captionlocation,...) 。WPF綁定:綁定對象的訪問子屬性

我寫了一個控制模板,我的控制,我需要訪問Tag的屬性(captionlocation,...等),所以我使用RelativeSourceTemplatedParent綁定,並作爲Path我已經試過用Path=Item.Tag.caption如下:

<ControlTemplate TargetType="y:myControl"> 
    <Rectangle> 
     <Rectangle.Fill> 
      <SolidColorBrush 
       Color="{Binding RelativeSource={RelativeSource TemplatedParent}, 
       Path=Item.Tag.caption}" /> 
     </Rectangle.Fill> 
    </Rectangle> 
</ControlTemplate> 

但我收到以下錯誤:沒有找到 Tag財產「object」,因爲data item is null,我沒有得到結果。

+1

你確定你有項目屬性有效值?你如何以及何時設置它? Item屬性的源代碼會有所幫助。 – jure 2013-05-14 16:53:47

+0

是的,請發佈您的控制代碼。 – 2013-05-14 17:12:21

+0

實際上我使用的是wff的yfiles庫,而控件是[EdgeSegmentControl](http://docs.yworks.com/yfileswpf/html/AllMembers_T_yWorks_yFiles_UI_Drawing_EdgeSegmentControl.htm),'Tag'屬性是'IEdge'的一部分接口,所以我想我需要將'Item'作爲'IEdge'來訪問 – Aminouvic 2013-05-14 18:17:34

回答