views:

28

answers:

2

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?

+1  A: 

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

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

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.

Julian Dominguez
Well, my application needs to update the business object 'person' each time the user changes the value of the control (numericUpDown). And i can do this just fine in the code behind, but i was just wondering if i could store the object as a resource and do something like what i mentioned in the question to update it. I'm just experimenting with wpf and i'm sure its a stupid idea.
smkngspcmn