Raised event of InteractionRequest becomes null

Topics: Prism v4 - WPF 4
Apr 14, 2015 at 12:10 PM
Hi,
I am working on WPF PRISM 5.0. I am using Popup of PRISM. I have done some customization in popup. I am facing one issue. I am using RequestNavigate to move from one user control to another.
So when I move from one user control to another, Raised event of InteractionRequest becomes null and popup doesn't open.

Below is some of the code snippet from my application.

UserControl1.xaml

<in:Interaction.Triggers>
    <prism:InteractionRequestTrigger x:Uid="prism:InteractionRequestTrigger_1" SourceObject="{Binding ConfirmationRequest, Mode=OneWay}">
        <Popup:PopupWindowAction x:Uid="prism:PopupWindowAction_1" IsModal="True" CenterOverAssociatedObject="True" Width="350" Height="150">
        </Popup:PopupWindowAction>
    </prism:InteractionRequestTrigger>
</in:Interaction.Triggers>

ViewModel.cs

this.ConfirmationRequest = new InteractionRequest<PopupConfirmation>();

public InteractionRequest<PopupConfirmation> ConfirmationRequest { get; private set; }


this.ConfirmationRequest.Raise(
            new PopupConfirmation { Content = "Hi", Title = "Confirm" },
            OnConfirmation);

In the above code after navigate to other user control and coming back here, Raised event of this.ConfirmationRequest becomes null. It works everytime if I don't navigate to other user control.

Kindly help me what's the issue here.

Thanks,
Ayaz Shaikh
Apr 14, 2015 at 12:17 PM
If you can provide a full repro (not just snippets - need to be able to download and run and see the problem) in an issue at http://github.com/prismlibrary we can look at fixing in our next release if it is a Prism problem.
Thanks
Brian
Apr 22, 2015 at 8:10 AM
@BrianNoyes, Sorry for late reply...
I resolved this issue. The issue was that for user control I haven't assigned the viewModel explicitly and it was using the viewModel of it's parent view. So to resolved this issue, I have explicitly injected view model to the child user control.
So while registering my code was:

// Register ViewModel
this.container.RegisterType<IParentViewModel, ParentViewModel>("ParentviewModel", new ContainerControlledLifetimeManager());

// Register View
this.container.RegisterType<object, ParentView>("ParentView", new InjectionConstructor(new ResolvedParameter<IParentViewModel>("ParentViewModel")));
this.container.RegisterType<object, UserControl1View>("UserControl1View");
this.container.RegisterType<object, UserControl2View>("UserControl2View");
So in the above code I haven't explicitly injected the view model for UserControl1View and UserControl2View and it was using ParentViewModel.

To resolve this issue I have explicitly injected view Model as below and it works.

// Register View
this.container.RegisterType<object, ParentView>("ParentView", new InjectionConstructor(new ResolvedParameter<IParentViewModel>("ParentViewModel")));
this.container.RegisterType<object, UserControl1View>("UserControl1View", new InjectionConstructor(new ResolvedParameter<IParentViewModel>("ParentViewModel")));
this.container.RegisterType<object, UserControl2View>("UserControl2View", new InjectionConstructor(new ResolvedParameter<IParentViewModel>("ParentViewModel")));

So what's the issue with Raised event in PRISM popup if we don't explicitly inject view model.

Thanks,
Ayaz Shaikh
Marked as answer by ayazshaikh1983 on 4/27/2015 at 3:47 AM
Apr 27, 2015 at 10:50 AM
@BrianNoyes - Kindly let me know if any update on above post. Although I have marked it as Answer, kindly let me why Raised event become NULL after requestNavigate when we don't provide explicit viewmodel to child view.

Thanks,
Ayaz Shaikh
Apr 27, 2015 at 1:01 PM
Could you please post this as an issue with your background detail in our new repo at http://github.com/PrismLibrary/Prism?
Thanks
Brian
Aug 10, 2015 at 9:34 PM
Hello Brian,

We have a similar issue but the resolution [RegionMemberLifetime(KeepAlive = false)] is not helping here.

We have a view that opens a UserControl (UC1) as a popup using InteractionRequest<INotification>.
        UC1ViewRequest.Raise(new UC1ViewModel
        {
            Title = "User Control 1"

        });
UC1 has a button that opens another UserControl (UC2) as a popup using InteractionRequest<INotification>.
        UC2ViewRequest.Raise(new UC2ViewModel
        {
            Title = "User Control 2"

        });
Opening UC2 again and again from UC1 works fine as long as UC1 is not closed.

But after closing UC1, UC2 cannot be shown/opened from UC1 but UC1 can be opened again from the main view.

The Raised event on the UC2ViewRequest is null.

Please advise. I can send you a sample to reproduce.