2017-06-27 72 views
0

我有一个场景。我正在使用Prism 6.0编写一个WPF应用程序,我想首先弹出一个子窗口,它将有三个按钮用于三种不同的UI设计。类似这样。我们将更新MainWindowViewModel,并关闭子窗口,并显示MainWindow我如何使用Prism 6设置WPF应用程序中的两个内容区域6

直到这部分是好的。但问题出在这部分之后,三个不同的按钮指向三种不同的UI设计。特别是ContentRegion1和ContentRegion2。这两个地区是不同的。

我已经看到,如果我通过一个按钮发出一个命令,那么这段代码运行成功。但是,如果我把它放在MainWindowViewModel中,也是一样。

public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) 
{ 
    _regionManager = regionManager; 
    _eventAggregator = eventAggregator; 
    _regionManager.RequestNavigate("ContentRegion1", "firstUiDesign"); 

... 

} 

这样的MainWindowlooks ...

enter image description here

ContentRegion1和ContentRegion2是两个设计在XAML这样

<Border CornerRadius="15" Grid.Column="0"> 
    <StackPanel> 
     <ContentControl prism:RegionManager.RegionName="ContentRegion1" /> 
    </StackPanel> 
</Border> 
<Border CornerRadius="15" Grid.Column="1"> 
    <StackPanel Grid.Column="1" Margin="2"> 
     <ContentControl prism:RegionManager.RegionName="ContentRegion2" /> 
    </StackPanel> 
</Border> 

但是我无法找出我做错了什么,还有什么额外的东西,我需要把代码放到工作中。

即使在BootStrapper.cs我也有这样的代码

引导程序代码:

protected override DependencyObject CreateShell() 
{ 
    //return base.CreateShell(); 
    return Container.Resolve<MainWindow>(); 
} 

protected override void InitializeShell() 
{   
    Application.Current.MainWindow.Show(); 
} 

protected override void ConfigureContainer() 
{ 
    base.ConfigureContainer(); 
    Container.RegisterTypeForNavigation<TestUserControl>("firstUiDesign"); 

} 

可以在这个任何人的帮助。

+0

所以你的问题是,你不能显示在firstUiDesign视图ContentRegion1?你的引导程序是如何实现的? – mm8

+0

我已经用Bootstrapper代码更新了我的源代码 – Debhere

+0

您在哪里创建MainWindowViewModel?您是否使用ViewModelLocator为您创建它? – mm8

回答

1

请勿使用ViewModelLocator来创建MainWindowViewModel。自己在BootstrapperMainWindow和地区建立它已创建:

protected override DependencyObject CreateShell() 
{ 
    return Container.Resolve<MainWindow>(); 
} 

protected override void InitializeShell() 
{ 
    var mainWindowViewModel = Container.Resolve<MainWindowViewModel>(); 
    Application.Current.MainWindow.DataContext = mainWindowViewModel; 
    Application.Current.MainWindow.Show(); 
} 

protected override void ConfigureContainer() 
{ 
    base.ConfigureContainer(); 
    Container.RegisterTypeForNavigation<TestUserControl>("firstUiDesign"); 
} 

MainWindow.xaml删除此:

prism:ViewModelLocator.AutoWireViewModel="True"> 
+0

这是一个不错的解决方案,我会尝试,但目前我已经用以下方式解决了它。在MainWindowViewModel中,我在构造函数中具有以下代码:this._regionManager.RegisterViewWithRegion(“ContentRegion1”,typeof(firstUiDesign));' 这样,它在运行时显示FirstUiDesign。无论如何感谢您指出Prism ViewModelLocator – Debhere

相关问题