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?
1 Answer
The solution for the problem, finally, is to use following syntax:
Path=Item.(myNameSpace:IEdge.Tag).caption 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) As suggested in comments Do not use shorthand binding syntax when using this solution. Ensure you actually use Path= otherwise it won't work!
12 Comments
Libor
Okay, I made it work but still - where you found this information? It seems like some WPF under-the-hood undocumented black magic...
Aminouvic
@Libor : Actually I found the solution on msdn PropertyPath XAML Syntax using Property partial qualification see section Single Property, Attached or Otherwise Type-Qualified
zastrowm
web.archive.org/web/20120814100526/http://msdn.microsoft.com/… for those of us in 2015 where the link that @Aminouvic posted no longer exists.
Andrew Stakhov
Do not use shorthand binding syntax when using this solution. Ensure you actually use Path= otherwise it won't work.
M.kazem Akhgary
what if I just want to cast. and not access property like just
Item.(myNameSpace:IEdge)? this fails it wants me to access property of IEdge but I just wanted to cast Item to IEdge? |
Itemis implementingIEDGEandTagis a property, it should work like you've posted it. What error are you getting?Itemis of typeobject, then I am getting an error thatTagproperty not found forobject