[英]How can I set two Content region in a WPF apps using Prism 6
我有一個場景。 我正在使用Prism 6.0編寫WPF應用程序,我想在其中首先彈出一個子窗口,該子窗口將具有用於三個不同UI設計的三個按鈕。 像這樣。
基於選擇,我將更新MainWindowViewModel
並關閉子窗口,並顯示MainWindow
。
直到這部分是好的。 但是問題出在這部分之后,三個不同的按鈕指向三種不同的UI設計。 特別是ContentRegion1和ContentRegion2。 這兩個區域是不同的。
我已經看到,如果我通過Button輸入命令,那么此代碼將成功運行。 但是如果我將它放在MainWindowViewModel
,則不會運行相同的命令。
public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
{
_regionManager = regionManager;
_eventAggregator = eventAggregator;
_regionManager.RequestNavigate("ContentRegion1", "firstUiDesign");
...
}
MainWindow看起來像這樣...
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中,我也有此代碼
BootStrapper代碼:
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");
}
任何人都可以幫忙。
不要使用ViewModelLocator
創建MainWindowViewModel
。 在MainWindow
和區域創建完成后 ,在Bootstrapper
自己創建它:
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">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.