Bind WPF control with property of custom type
Posted
by TheBlueSky
on Stack Overflow
See other posts from Stack Overflow
or by TheBlueSky
Published on 2010-05-21T07:37:34Z
Indexed on
2010/05/21
7:40 UTC
Read the original article
Hit count: 148
wpf-binding
Hello everyone,
I'm trying to bind a Label's 'Content' property to a property from some custom type I have; unfortunately, I didn't figure out how to do it, and that's why I'm here :)
Let's assume that I have the following type (can be in the same namespace as my WPF Window that contains the Label or different namespace):
namespace MyNS
{
pubic class Person
{
private int age = 0;
public int Age
{
get { return age; }
}
public void GetOlder
{
age++;
}
}
}
1) How to I bind my Label to 'Age' property?
2) At runtime I will create an instance of 'Person'; I want to make sure that my Label is bound to the right instance; i.e. if I called:
Person SomePerson = new Person();
SomePerson.GetOlder();
I want my Lable to have the new value of 'Age' property for 'SomePerson'.
3) If #2 was possible (I hope so), what if I called 'GetOlder' in different thread? Will I still get the latest value of 'Age'? Or do I have to take care of some other things as well to make this scenario possible?
Thanks in advance,
TheBlueSky
© Stack Overflow or respective owner