2012-01-17 95 views
3

显示一个对话框窗口,我有两个棱镜模块。 我想其中的一个注册窗口,使用“显示对话框”模式的另一个显示该窗口。 如何做(如果可以做到)?棱镜:通过两个模块

回答

1

嘛。我想我通过遵循this tip来解决它。但我不知道这是否是最好的解决方案。

我刚刚创建我的壳牌项目的窗口。这个窗口将会弹出一个对话窗口。

下面是它的代码:

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:

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; 
    } 
} 

最后,当我想显示对话框(在一个命令,它是在一个模块中),我只是实例并告知什么是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(); 
} 
1

是的,是可以做到的。这是大概步骤:

申报界面这一观点在“基础设施”项目

public interface IMyDialogWindow 
{ 
} 

[出口]类,你的模块

[Export(typeof(IMyDialogWindow))] 
public class MyClassInModuleA : IMyDialogWindow 
{ 
} 

[导入]这个类实现此接口在其他模块,并使用它的对话框

[Import] 
public IMyDialogWindow PropertyInModuleB 
+0

你可以发布一些示例代码?我完全无法理解你的答案。我必须复制另一个项目中的文件?我正在考虑以何种方式将视图注册到第一个模块的IoC容器中,然后“读取”并在第二个模块上显示。 – 2012-01-18 01:01:40

+0

您必须通过可以放置在“基础设施”模块中的接口“粘合”ModuleA和ModuleB。通过这种方式,ModuleB将能够在不知道它的情况下从ModuleA导入窗口。 – katit 2012-01-18 01:31:22

+0

谢谢。它是否可以与Unity一起使用? – 2012-01-18 12:14:29