48

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?

4
  • Are you doing this in code or in Xaml? Commented May 15, 2013 at 8:51
  • I need to do this in Xaml Commented May 15, 2013 at 9:12
  • @Aminouvic If Item is implementing IEDGE and Tag is a property, it should work like you've posted it. What error are you getting? Commented May 15, 2013 at 9:34
  • @DHN the problem is that during binding Item is of type object, then I am getting an error that Tag property not found for object Commented May 15, 2013 at 9:40

1 Answer 1

90

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!

Sign up to request clarification or add additional context in comments.

12 Comments

Okay, I made it work but still - where you found this information? It seems like some WPF under-the-hood undocumented black magic...
@Libor : Actually I found the solution on msdn PropertyPath XAML Syntax using Property partial qualification see section Single Property, Attached or Otherwise Type-Qualified
web.archive.org/web/20120814100526/http://msdn.microsoft.com/… for those of us in 2015 where the link that @Aminouvic posted no longer exists.
Do not use shorthand binding syntax when using this solution. Ensure you actually use Path= otherwise it won't work.
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?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.