How do I implement IActivationForViewFetcher for a child UserControl?
Asked Answered
S

3

6

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?

Schechinger answered 6/7, 2016 at 5:20 Comment(0)
S
1

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!

Schechinger answered 7/7, 2016 at 3:49 Comment(6)
I got the same problem for my Xamarin Droid project. When I call this.WhenActivated I get the same error message that you described above. However, in my Xamarin iOS project everything is working fine. Can you explain a little bit more detailed how you have solved the problem?Tutt
In my case (from memory) I had to reference the ReactiveUI assemblies in my main assembly (as well as the libraries). This then calls ReactiveUI.Winforms.Registrations which sets up the default handlersSchechinger
Because I'm using Winforms, I can't use WhenActivated anyway (unless that's changed recently). So I may have avoided the problem you're facingSchechinger
Ok, thanks for your fast reply. I think my problem must be somewhere in the setup of my Android project because a colleague of mine is using ReactiveUI 7.0 in another Android project and for him it's working fine. Or maybe it's a bug in 7.1.0 but that's something I still have to confirm yet.Tutt
in other words you have to also add the nuget package reactiveui-winforms to your project. In References I now see ReactiveUI.Winforms and all is working.Rycca
This is discussed in ReactiveUI ussue #1016 github.com/reactiveui/ReactiveUI/issues/1016 It looks like they fixed it. I came upon it because I'm still using ReactiveUI 7.2.0. I could not even add a UserControl to a View.Selflove
Y
0

I don't if this will ever help anybody, since this thread is so old.

What solved my issue was having ReactiveUI.WPF,ReactiveUI.WinForms, CefSharp.WPF and CefSharp.WinForms NuGet references on all the projects/plugins that were running on the App.

My suspicion is that when ReactiveUI/CefSharp is initialized and it doesn't contain all the info/files it needs, it will not possible to add them later on runtime. But this is just guessing based on my experience.

Yearbook answered 20/8, 2020 at 14:16 Comment(0)
T
0

I know it's an old thread, but just to save other developers time when facing this problem.

My solution was to add the following code in the entrypoint of the project that makes use of ReactiveUi and ReactiveUi.Wpf.

var reactiveUiWpfName = typeof(ReactiveUI.Wpf.Registrations).Assembly.FullName;
Assembly.Load(reactiveUiWpfName);

Of course, it was just required because I couldn't reference ReactiveUi or ReactiveUi.Wpf in my application startup project due to the project specifications, otherwise this error wouldn't appear anyway.

(Please, observe that, in your case you should use ReactiveUi.Winforms in the places I've used ReactiveUi.Wpf)

Tarsal answered 12/11, 2021 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.