Skip to content

[BUG] WPF: WhenActivated not fired when in ViewModelViewHost #2021

@zperak

Description

@zperak

Describe the bug
In version 9.14.1, in commit [a1cb284] MSBuild.Sdk.Extras was updated to v2.0.24 (from 1.6.68). Also ExtrasEnableWpfProjectSetup tag is changed to UseWpf.
After these two changes in WPF project, WhenActivated event does not fire when loaded into ViewModelViewHost.
When MSBuild.Sdk.Extras is rolled back to version 1.6.68 and UseWpf changed back to ExtrasEnableWpfProjectSetup in ReactiveUI.Wpf/ReactiveUI.Wpf.csproj then everything works again, i.e. this.WhenActivated in view loaded into ViewModelViewHost fires again.

Steps To Reproduce
In attached simple WPF project (DebugWhenActivated.zip):

  1. In App.xaml.css add: Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());
  2. In MainWindow.xaml add ViewModelViewHost
  3. In MainWindow.xaml.cs bind ViewModelViewHost.ViewModel with MainDocViewModel which is ViewModel for MainDocView.xaml (Reactive)UserControl

Expected behavior

  1. ViewModelViewHost loads MainDocView.xaml
  2. In MainDocView.xaml.cs constructor this.WhenActivated is fired

Actual behavior

  1. The same
  2. this.WhenActivated is not fired

Environment

  • OS: Windows 10
  • Version 1809
  • Device: PC laptop
  • IDE: Visual Studio 2019 Enterprise

Additional context
To investigate issue, I have added ReactiveUI and ReactiveUI.Wpf as projects dependencies to my test app (DebugWhenActivated). I had to remove most targets from ReactiveUI.csproj to be able to compile project.
You can get the same result if you add dependency via NuGet: Version 9.13.1 works ok and in 9.14.1 this.WhenActivated does not work if loaded into ViewModelViewHost.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions