交互 - IInteractionRequestAware 属性未填充

Interaction - IInteractionRequestAware properties not populating

我试图在它自己的模块中创建一个自定义弹出窗口,这导致我遇到以下情况(ContentControl inside PopupWindowAction):

<i:Interaction.Triggers>
    <prism:InteractionRequestTrigger SourceObject="{Binding Path=MyRequest, Mode=OneWay}">
        <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
            <prism:PopupWindowAction.WindowContent>
                <ContentControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.MyRegion}"/>
            </prism:PopupWindowAction.WindowContent>
        </prism:PopupWindowAction>
    </prism:InteractionRequestTrigger>
</i:Interaction.Triggers>

视图很好地加载到弹出 window 但 IInteractionRequestAware 属性(Notification FinishInteraction) 在视图和视图模型上都为空。

这是设置这些属性的 Prism 源代码:

    /// <summary>
    /// Checks if the WindowContent or its DataContext implements <see cref="IInteractionRequestAware"/>.
    /// If so, it sets the corresponding value.
    /// Also, if WindowContent does not have a RegionManager attached, it creates a new scoped RegionManager for it.
    /// </summary>
    /// <param name="notification">The notification to be set as a DataContext in the HostWindow.</param>
    /// <param name="wrapperWindow">The HostWindow</param>
    protected virtual void PrepareContentForWindow(INotification notification, Window wrapperWindow)
    {
        if (this.WindowContent == null)
        {
            return;
        }

        // We set the WindowContent as the content of the window. 
        wrapperWindow.Content = this.WindowContent;

        Action<IInteractionRequestAware> setNotificationAndClose = (iira) =>
        {
            iira.Notification = notification;
            iira.FinishInteraction = () => wrapperWindow.Close();
        };

        MvvmHelpers.ViewAndViewModelAction(this.WindowContent, setNotificationAndClose);
    }

这是否意味着正在检查 ContentControl 对象以查看它是否实现了 IInteractionRequestAware 而不是我的视图或视图模型?

是否可以使用区域管理器指定一个自定义弹出视图,其中包含所有注入,并且还设置了 IInteractionRequestAware 属性?

你有两个选择;创建一个实现适当接口的自定义 ContentControl。或者,改为创建和使用对话服务。我实际上建议改用对话框服务,因为您想要更动态的弹出行为。 PluralSight 课程涵盖了对话服务 'Prism Problems & Solutions: Showing Multiple Shells'。