Prabath Yapa
Prabath Yapa

Reputation: 1229

wpf resource binding to another element's property

I'm new to WPF so pardon me if i'm asking something stupid. I have an class named Person in my application. Can i do something like

<local:Person x:Key="p" BirthYear="{Binding Path=Value, ElementName=year}"  /> 

where 'year' is a control?

Upvotes: 1

Views: 1624

Answers (2)

Julian Dominguez
Julian Dominguez

Reputation: 2583

No, you can't because resources are not part of the same naming container (and are added differently to the visual tree).

Why do you need to store a Person (business object I assume) as a resource, but having its value coming from another control? Maybe if you explain your motivation we can help you find a better alternative.

Upvotes: 1

benPearce
benPearce

Reputation: 38373

you are probably better off inverting your binding and binding the control to your class

<Control Value="{Binding Path=BirthYear}" DataContext="{StaticResource p}"/>

Upvotes: 1

Related Questions