Search code examples
c#wpfpopupprismregion

WPF,C#: Multiple declarations of popup creating problems


I have a Prism WPF app that uses popups. The same functionality is needed in multiple places, so I've got my popup referenced like so.

<i:Interaction.Triggers>
    <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CreateCatalogsRequest, Mode=OneWay}">
        <interactionRequest:PopupWindowAction>
            <interactionRequest:PopupWindowAction.WindowContent>

                <!-- Problem line below -->
                <view:SomePopUpView />

            </interactionRequest:PopupWindowAction.WindowContent>
        </interactionRequest:PopupWindowAction>
    </interactionRequest:InteractionRequestTrigger>
</i:Interaction.Triggers>

This exact same snippet of code appears in two controls at the moment. When I comment out the code, or replace "SomePopupView" with a standard component (Combobox) my app works. When I have it referencing the same component (SomePopupView) twice, my app chokes complaining about regions.

I don't want to have to rewrite or extend or do any architecture voodoo, but how do I get the same popup functionality in different parts of the app?

Any help is greatly appreciated

EDIT The solution as provided by AnjumSKhan works. My solution is as follows

App.xaml

<Application.Resources>
    <view:SomePopupView x:Key="SomePopupView" />
    ....
<Application.Resources>

View with duplicated popup

<i:Interaction.Triggers>
    <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CreateRequestInteraction, Mode=OneWay}">
        <interactionRequest:PopupWindowAction>
            <interactionRequest:PopupWindowAction.WindowContent>
                <ContentControl Content="{StaticResource SomePopupView}"></ContentControl>
            </interactionRequest:PopupWindowAction.WindowContent>
        </interactionRequest:PopupWindowAction>
    </interactionRequest:InteractionRequestTrigger>
</i:Interaction.Triggers>

Solution

  • Solution.

    App.xaml

    <Application.Resources>
        <view:SomePopupView x:Key="SomePopupView" />
        ....
    <Application.Resources>
    

    View with duplicated popup

    <i:Interaction.Triggers>
        <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CreateRequestInteraction, Mode=OneWay}">
            <interactionRequest:PopupWindowAction>
                <interactionRequest:PopupWindowAction.WindowContent>
                    <ContentControl Content="{StaticResource SomePopupView}"></ContentControl>
                </interactionRequest:PopupWindowAction.WindowContent>
            </interactionRequest:PopupWindowAction>
        </interactionRequest:InteractionRequestTrigger>
    </i:Interaction.Triggers>