WPF棱镜区域经理问题

编程入门 行业动态 更新时间:2024-10-28 07:29:34
本文介绍了WPF棱镜区域经理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:mui="firstfloorsoftware/ModernUI" xmlns:prism="www.codeplex/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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:mc="schemas.openxmlformats/markup-compatibility/2006" xmlns:d="schemas.microsoft/expression/blend/2008" xmlns:mui="firstfloorsoftware/ModernUI" xmlns:prism="www.codeplex/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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:cal="www.codeplex/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 { }

截屏:

您可以下载我的示例: 1drv.ms/1mEtNIX

You could download my sample: 1drv.ms/1mEtNIX

这是类似的问题:

#RegionManager空(不继承) compositewpf.codeplex/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棱镜区域经理问题

本文发布于:2023-11-06 14:54:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:棱镜   区域经理   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!