WPF 绑定:在绑定路径中进行转换 [英] WPF Binding : Casting in binding path
问题描述
我有一个绑定,其中 Path
设置为 Path=Item.Tag.caption
,但我需要将 Item
转换为IEDGE
首先,以便我可以访问 Tag
属性.有没有办法做到这一点?
I've a binding where the Path
is set to Path=Item.Tag.caption
, but I need to cast Item
to IEDGE
first so I can access the Tag
Property.
Is there a way to achieve this?
推荐答案
问题的解决方案,最后是使用以下语法:
The solution for the problem, finally, is to use following syntax:
Path=Item.(myNameSpace:IEdge.Tag).caption
前面的代码将 Item
转换为 IEdge
类型以访问 Tag
属性.
The previous code cast Item
to the type IEdge
in order to access the Tag
property.
在多个嵌套强制转换的情况下,全局模式是:
In case of multiple nested casts the global pattern is :
Path=Obj1.(ns1:TypeObj1.Obj2).(ns2:TypeObj2.Obj3)...(nsN:TypeObjN.BindedProp)
如评论中所建议在使用此解决方案时不要使用速记绑定语法.确保您确实使用了 Path=
否则它将无法工作!
As suggested in comments Do not use shorthand binding syntax when using this solution. Ensure you actually use Path=
otherwise it won't work!
这篇关于WPF 绑定:在绑定路径中进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!