棱镜:通过两个模块显示对话框窗口 [英] Prism: Showing a dialog window through two modules

查看:105
本文介绍了棱镜:通过两个模块显示对话框窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个棱镜模块. 我希望其中一个注册一个窗口,另一个希望使用显示对话框"模式显示此窗口. 怎么做(如果可以的话)?

I have two Prism modules. I want one of them register a window and the other one show this window using the "Show Dialog" mode. How can it be done (if it can be done)?

推荐答案

好.我想我可以通过此提示解决.但是我不知道这是否是最好的解决方案.

Well. I think I solved it by following this tip. But I don't know if it was the best solution.

我刚刚在Shell项目上创建了一个窗口.该窗口将作为对话框窗口弹出.

I just created a window on my Shell project. This window is the one that will be popped up as a dialog window.

这是它的代码:

Popup.xaml:

Popup.xaml:

<Window x:Class="TryERP2.Shell.Views.Popup"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Popup" Height="315" Width="411"
        xmlns:prism="http://www.codeplex.com/prism">
    <Grid>
        <ContentControl x:Name="DialogRegion" Grid.Row="1" prism:RegionManager.RegionName="DialogRegion" />
    </Grid>
</Window>

Popup.xaml.cs:

Popup.xaml.cs:

public partial class Popup : Window
{
    private static Popup popup;

    private Popup(IRegionManager regionManager)
    {
        InitializeComponent();
        RegionManager.SetRegionManager(this, regionManager);
    }

    //Using the singleton pattern
    public static Popup getPopup(IRegionManager regionManager)
    {
        if (popup == null)
            popup = new Popup(regionManager);
        return popup;
    }
}

最后,当我想显示对话框(在模块中的Command中)时,我将其实例化并告知什么是RegionManager:

And, finally, when I want to show the dialog (in a Command which is in a module), I just instantiate it and inform what's the RegionManager:

private void showDialog()
{
    // Acquiring the RegionManager
    var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();

    // Getting the Popup object
    Popup p = Popup.getPopup(regionManager);

    // Looking for the view I want to show in the dialog
    var x = new Uri("MyView", UriKind.Relative);

    // Changing the view of the DialogRegion (which is within the Popup)
    regionManager.RequestNavigate("DialogRegion", x);

    // Showing the dialog
    p.ShowDialog();
}

这篇关于棱镜:通过两个模块显示对话框窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆