0

I have a xaml text block defined like this:

 <TextBlock HorizontalAlignment="Left" Margin="307,43,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="105" Width="230" Text="{Binding Supplier}"/>

I'm trying to bind to the property Supplier.

My constructor for the Xaml window code-behind class:

InitializeComponent();
viewModel = new NewOrderViewModel();
DataContext = viewModel;

There I explicitly set DataContext to be my viewModel object, which contains Supplier property.

And my viewModel prop:

public SupplierDto Supplier
        {
            get
            {
                return supplier;
            }
            set
            {
                supplier = value;
            }
        }

Isn't this all I have to do (set DataContext to an appropriate object), and have all public properties available for binding as I see fit?

1

1 Answer 1

2

Your viewmodel has to implement INotifyPropertyChanged and you have to call NotifyPropertyChanged() method in Supplier setter.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, as someone new to WPF, things at start can be very confusing :)

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.