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?

Mitkins
  • 4,031
  • 3
  • 40
  • 77

3 Answers3

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!

Mitkins
  • 4,031
  • 3
  • 40
  • 77
  • 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? – jfmg Jan 17 '17 at 08:58
  • 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 handlers – Mitkins Jan 17 '17 at 11:05
  • 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 facing – Mitkins Jan 17 '17 at 11:12
  • 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. – jfmg Jan 17 '17 at 12:58
  • 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. – penCsharpener Apr 03 '18 at 11:12
  • This is discussed in ReactiveUI ussue #1016 https://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. – user1040323 Oct 12 '18 at 12:46
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.

JPRLCol
  • 749
  • 11
  • 28
Gon
  • 1
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)