Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of ReactiveUI's IViewFor<T> (and its implementing types) in WPF? [closed]

Tags:

c#

wpf

reactiveui

I am in the process of learning ReactiveUI and so far I love it but I now realise that the framework encompasses XAML (i.e. the view layer) as well, offering things like ReactiveUserControl and ReactiveView.

Why do I need, or want these? System.Reactive/ReactiveUI offer massive advantages on the Model/ViewModel side but what are the advantages on the View side, again, in the context of a WPF app? Unit testing perhaps?

Note: I like WPF, I like its data binding. All my XAML bindings are strongly-typed and easy to refactor, customise, re-skin, debug and whatnot. I learned to use but not over-use the converters so never have a prob with those either. I never felt a need to override the UserControl class. With that said, I never had a problem with the WPF itself.

If I decide to use the IVIewFor<T> implementations, will my XAML designer go nuts? Will I lose anything? Will I end up debugging memory leaks, UI stutter and strange CPU spikes? We'll be making a very large app so we go by the 'better safe than sorry' principle as we were burnt by the CAB framework before.

If I decide against, what benefits of the ReactiveUI will we lose? Would I be heathens for doing this, or is it more of an optional aspect of the framework?

So far I understand the benefits in case of WinForms or Android (it offers binding support as I understood) but not WPF. While it sure does have its quirks, I don't feel the need for another framework on top of it.

like image 509
bokibeg Avatar asked Dec 07 '25 05:12

bokibeg


1 Answers

You would implement IViewFor<T> when you for example want to set up bindings in the view and when you want to handle activation and deactivation, e.g.:

this.WhenAnyValue(x => x.ViewModel.Name).BindTo(this, view => view.Name.Text);

this.WhenActivated(d => { /* do something */});

These methods are implemented as extension methods. Please refer to the docs for more information and examples:

https://reactiveui.net/docs/handbook/data-binding/ https://reactiveui.net/docs/handbook/when-activated/

Of course you don't have to use all features of ReactiveUI. It's perfectly fine to set up bindings in the XAML markup as usual and still bind to ReactiveObjects.

like image 124
mm8 Avatar answered Dec 08 '25 19:12

mm8