Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement IActivationForViewFetcher for a child UserControl?

I've just added ReactiveUI to an existing code base. Of course, for the first control I tried it with I hit a snag. I'm using it with a UserControl embedded in a TabControl. The code looks something like this:

public partial class TabPageControl : UserControl, IViewFor<TestViewModel>
{
    public TabPageControl()
    {
        InitializeComponent();

        ViewModel = new TestViewModel();

        this.WhenActivated(dispose =>
        {
            dispose(this.Bind( ... ));
            dispose(this.BindCommand( ... ));
        });
    }
}

When I run the app, I get the following error message:

Don't know how to detect when TabPageControl is activated/deactivated, you may need to implement IActivationForViewFetcher

So, how do I implement IActivationForViewFetcher? I'm not sure what I'm supposed to do with GetAffinityForView. I'm assuming in GetActivationForView I need to check to see if the UserControl is the currently visible inside the TabControl?

like image 609
Mitkins Avatar asked Jul 06 '16 05:07

Mitkins


Video Answer


1 Answers

Although I would like to understand how to implement the methods for IActivationForViewFetcher (especially the part where I identify that a control is in the VisualTree) - the real cause of my problem was that my main assembly didn't have the appropriate references (the controls are in a class assembly).

I'm assuming (because I've skimmed the ReactiveUI source) ReactiveUI.Winforms.Registrations needs to be instantiated by the main assembly - which includes registering ActivationForViewFetcher.

Incidentally, the class library is written in C# and the main assembly is VB.NET. So I'm not sure whether this contributed to the problem.

At least it's working now!

like image 98
Mitkins Avatar answered Sep 28 '22 21:09

Mitkins