Search code examples
c#wpfxamlreactiveuirx.net

WPF ReactiveUI bindings in View


I'm creating a WPF application using Rx and ReactiveUI. Do I have to bind properties from the view in code behind reactively or is the classic way good? I know binding between View and ViewModel objects, I just can't figure out if there should be a different way for these xaml bindings.

<Label x:Name="FilterLabel"
   ...
   Width="{Binding ActualWidth, ElementName=TemplateLabel}"
   .../>

Is this ok or is there a more "pro" way?

this.WhenActivated(d => {
    this.OneWayBind(ViewModel, vm => vm.Toolbar,   v => v.ToolbarView.ViewModel).DisposeWith(d);
});

This is how I do my ViewModel -> View bindings


Solution

  • If you're simply binding a view property to another in your Xaml, then in that case you're fine to stick with Xaml. But definitely stick to code-behind for View-ViewModel bindings, keeps your Xaml file cleaner and you also get the benefit of type-checking by using C# bindings.