我有一个名为Item
的{{1}}属性的控件,
X
有一个名为Item
的{{1}}类型的属性,Tag
有一些其他属性(Y
,Tag
,...)。
我为我的控件编写了一个控件模板,我需要访问caption
的属性(location
,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
并且我没有收到任何结果。
答案 0 :(得分:2)
解决方案是在访问属性之前在Path
变量中执行强制转换,如下所示:Path=Item.(myNameSpace:X.Tag).(myNameSpace:Y.caption)
有关详细信息,请查看WPF Binding : Casting in binding path