Skip to main content
  1. About
  2. For Teams
Asked
Viewed 1k times
1

When is the "Path=" xaml syntax required when specifying a binding to a property? I see this "Path=" pretty much exclusively when there is a nested property binding (ex: Path=Person.FirstName).

Thanks!

2 Answers 2

3

Think of it like initializing a class in C#. If the "Binding" class has a constructor that takes a path, you could do this:

new Binding("Person.FirstName");

... or this:

new Binding { Path = "Person.FirstName" };

The two are the same, for all intents and purposes. XAML is doing the same thing. If you omit the "Path=" you're passing a path into the constructor for Binding, but if you include it you're setting the value after the fact.

I often leave the "Path=" out, especially if I'm declaring a binding with no other properties set, like {Binding FirstName}.

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

4 Comments

Cool. I also leave the Path part out for simple properties. So does this mean I could also leave it out when binding something like this: {Binding Person.FirstName} ???
Yep, you definitely can. You can even include other attributes, like {Binding Person.FirstName,Converter={StaticResource NameConverter}}.
Ok Matt. I think i MIGHT have found my problem. But let me ask you this before I jump up and down. Will nested property binding work if, say FirstName, is a property that exists in a base class (not directly owned by the Person class)? If not, then this would answer my problem.
Yep, that's fine. It would have to be a public property, but it doesn't matter where it's defined in the class hierarchy.
0

You use this when the object you are binding to is not the same object that is set to the control's DataContext property

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.