-2

I'm making an application in WPF with ReactiveUI. I have a UserControl with a view model that has a property called Title, which is a string. How can I assign that property in XAML in the MainWindow view?

milkwood1
  • 385
  • 2
  • 3
  • 16

1 Answers1

0

You can bind to a public property of the current DataContext using the {Binding} markup extension in XAML regardless of whether you're using ReactiveUI or not:

<TextBlock Text="{Binding Title}" />

ReactiveUI does also provide a way to bind to properties programmatically:

public YourControl()
{
    InitializeComponent();
    this.WhenActivated(disposables =>
    {   
        this.Bind(ViewModel, vm => vm.Title, v => v.textBlock1.Text)
            .DisposeWith(disposables);
    });
}

Please refer to the docs for more informatiom.

mm8
  • 163,881
  • 10
  • 57
  • 88