我有一个带有名为 type 的属性的控件,有一个名为Item
typeX
的
属性Item
,还有一些其他属性(, ,...)。Tag
Y
Tag
caption
location
我已经为我的控件编写了一个控件模板,并且我需要访问Tag
' 的属性(caption
、location
、...等),所以我使用了 Binding with 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
我没有得到任何结果。