views:

34

answers:

2

Hi Let's say that I have a custom WPF control and couple of textboxes on it. In code behind of my custom control I have couple of properties which are references to objects in other control. For example I have a sth like this

public MyClass myObject
    {
        get
        {
            return MyObject
        }
    }

MyClass have a property Name. Is it possible to bind property Name to textBox.Text ??

I konow that I can do sth like that in XAML

<TextBox>
<TextBox.Text>
    <Binding Path="" />
 </TextBox.Text>
</TextBox>

But how can I pass data from myObject to Path value ??

A: 

Assuming that the DataContext is the same as your Control. The path will be

Path="myObject.MyPropery"

or for short

<TextBox Text="{Binding myObject.MyProperty}" />
hkon
thanks :) Let's say that I modify myObject.MyProperty. I understand that thanks to data binding my textbox will show new value or maybe I have to refresh textbox?
Dante
As long the property you bind to fires notifypropertychanged in it's setter, you should be fine
hkon
A: 

I've been experimenting with bindings but it seems that sometimes my textbox doesn't refresh/update Text property. I mean sometimes textbox refresh(I think) and I see new value but sometimes nothing happens (despite the fact that I modified data )

Dante
You don't need (nor should you) answer your own question when providing extra information - just edit the question.
ChrisF