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?
Asked
Active
Viewed 202 times
-2

milkwood1
- 385
- 2
- 3
- 16
-
Set the datacontext to the view model then use wpf binding – Glenn Watson Apr 10 '21 at 12:05
1 Answers
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