2
我有一个名为X
类型的Item
属性的控制, Item
有一个名为Y
类型的Tag
属性,和Tag
具有其他的一些性质(caption
,location
,...) 。WPF绑定:绑定对象的访问子属性
我写了一个控制模板,我的控制,我需要访问Tag
的属性(caption
,location
,...等),所以我使用RelativeSource
TemplatedParent
绑定,并作为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
,我没有得到结果。
你确定你有项目属性有效值?你如何以及何时设置它? Item属性的源代码会有所帮助。 – jure 2013-05-14 16:53:47
是的,请发布您的控制代码。 – 2013-05-14 17:12:21
实际上我使用的是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