WPF棱镜区域经理问题 [英] WPF Prism Region Manager Issue
问题描述
我正在尝试通过Prism学习WPF,并使用现代UI模板.我在使用区域管理器时遇到问题,无法在集合中找到区域,但是视图已正确注入.
I am trying to learn WPF with Prism and using Modern UI Template. I have Problem with region Manager, unable to find the region in collections but the views are getting injected properly.
这是我在做什么
步骤A:外壳窗口
<mui:ModernWindow x:Class="SimpleAccounting.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
xmlns:prism="http://www.codeplex.com/prism"
ContentSource="/PlaceHolders/AccountModulePlaceHolders/AccountListPlaceHolder.xaml"
>
<mui:ModernWindow.MenuLinkGroups>
<mui:LinkGroup DisplayName="Accounts">
<mui:LinkGroup.Links>
<mui:Link DisplayName="New Account" Source="/PlaceHolders/AccountModulePlaceHolders/NewAccountPlaceHolder.xaml">
</mui:Link>
<mui:Link DisplayName="Available Accounts" Source="/PlaceHolders/AccountModulePlaceHolders/AccountListPlaceHolder.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>
</mui:ModernWindow>
第2步:页面源或区域定义
Step 2 : Page Source or Region Definitions
<UserControl x:Class="SimpleAccounting.PlaceHolders.AccountModulePlaceHolders.AccountListPlaceHolder"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
xmlns:prism="http://www.codeplex.com/prism"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ContentControl Name="NameAccountListPlaceHoldersRegion" prism:RegionManager.RegionName="AccountListPlaceHoldersRegion" Grid.Row="0" Grid.Column="0"></ContentControl>
</UserControl>
第3步:我拥有具有以下功能的模块
Step 3 : I am having Module which have
public class SimpleAccountingModule : IModule
{
private readonly IRegionManager regionManager;
private readonly IUnityContainer container;
public SimpleAccountingModule(IRegionManager regionManager, IUnityContainer container)
{
this.regionManager = regionManager;
this.container = container;
}
public void Initialize()
{
regionManager.RegisterViewWithRegion("AccountListPlaceHoldersRegion", typeof(Views.AccountList));
}
}
第4步:运行应用程序完美无问题.
Step 4 : Run the application works perfect no issues.
步骤5:在步骤3中进行调试时,我的区域管理器计数始终为零,而当我尝试在其中查找元素时,找不到错误区域.但是,视图已正确注入.
Step 5: While debugging in Step 3 my region manager count is always zero, and when i am trying to find an element in it getting error region not found. However Views are getting injected properly.
感谢您的帮助
K K Sanghi
K K Sanghi
推荐答案
克里希纳,
您似乎应该在外壳程序窗口中添加ContentControl并设置RegionManager.RegionName,这是我的工作:
It looks like that you should add ContentControl and set RegionManager.RegionName in the Shell Window, here is what I do:
参考:棱镜4.1
项目1: HelloWorldModule
Views \ AccountList.xaml:
<Grid>
<TextBlock Text="AccountList" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Calibri" FontSize="24" FontWeight="Bold"></TextBlock>
</Grid>
SimpleAccountingModule.cs:
SimpleAccountingModule.cs:
public class SimpleAccountingModule : IModule
{
private readonly IRegionManager regionManager;
private readonly IUnityContainer container;
public SimpleAccountingModule(IRegionManager regionManager, IUnityContainer container)
{
this.regionManager = regionManager;
this.container = container;
}
public void Initialize()
{
regionManager.RegisterViewWithRegion("AccountListPlaceHoldersRegion", typeof(Views.AccountList));
}
}
项目2: HelloWorld.Desktop
Shell.xaml:
Shell.xaml:
<Window x:Class="HelloWorld.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/prism"
Title="Hello World" Height="300" Width="300">
<ContentControl Name="AccountListPlaceHoldersRegion" cal:RegionManager.RegionName="AccountListPlaceHoldersRegion" />
</Window>
Bootstrapper.cs:
class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return this.Container.Resolve<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)this.Shell;
App.Current.MainWindow.Show();
}
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
moduleCatalog.AddModule(typeof(HelloWorldModule.SimpleAccountingModule));
}
}
MainWindow.cs:
MainWindow.cs:
class MainWindow
{
}
截屏:
您可以下载我的示例: http://1drv.ms/1mEtNIX
You could download my sample: http://1drv.ms/1mEtNIX
这是类似的问题:
#RegionManager空(不继承)
http://compositewpf.codeplex.com/workitem/10276
由于该问题与该第三方产品更相关,因此您最好在其官方网站上提出问题以寻求进一步的支持.
Since this question is more related to this 3rd-party product, you'd better to ask question at its official website for further support.
这篇关于WPF棱镜区域经理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!