0

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 ??


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 )

1 Answer 1

0

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}" />
Sign up to request clarification or add additional context in comments.

2 Comments

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?
As long the property you bind to fires notifypropertychanged in it's setter, you should be fine

Your Answer

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.