2013-05-14 149 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

回答