【问题标题】:Interaction - IInteractionRequestAware properties not populating交互 - 未填充 IInteractionRequestAware 属性
【发布时间】:2015-10-19 20:20:00
【问题描述】:

我正在尝试在它自己的模块中创建一个自定义弹出窗口,这导致我出现以下情况(ContentControl 内 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>

视图很好地加载到弹出窗口中,但 IInteractionRequestAware 属性(Notification 和 FinishInteraction)在 View 和 View 上都是 null型号。

这是设置这些属性的 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 属性?

【问题讨论】:

    标签: c# wpf prism


    【解决方案1】:

    你有两个选择;创建一个实现正确接口的自定义 ContentControl。或者,创建并使用对话服务。实际上,我建议您使用对话服务,因为您希望拥有更动态的弹出行为。 PluralSight 课程“棱镜问题和解决方案:显示多个外壳”中介绍了对话服务。

    【讨论】:

    • 非常感谢您的回答。
    • 我正在做类似的事情并遇到了同样的问题。我通过子类化 PopupWindowAction 来解决它。对于任何感兴趣的人,我将其作为第三选择。
    猜你喜欢
    • 2014-12-06
    • 2014-08-27
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多