Microsoft Prism 应用程序需要帮助
我正在使用 MEF 创建一个新的 Prism4 应用程序,它运行良好。我已经创建了 Shell 等,一切正常。
但现在我需要创建一个新的窗口,其中包含一个区域,但该区域似乎没有向RegionManager注册(请参阅Window_Closing 事件)和窗口中的区域工作良好,因为显示了注入其中的视图。
的代码
这是新窗口Wizard.xaml
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
<Button Content="_Previous" Margin="0, 0, 10, 0" />
<Button Content="_Next" />
</StackPanel>
<ContentControl cal:RegionManager.RegionName="WizardStepsRegion" />
</DockPanel>
当我尝试获取窗口的区域时,出现以下异常“KeyNotFoundException 未由用户代码处理”、“区域管理器不包含 WizardStepsRegion 区域。 ”
Wizard.xaml.cs
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
object asdf = regionManager.Regions["WizardStepsRegion"];
}
为什么区域没有在区域管理器中注册?
有人可以帮助我吗?
谢谢。
I'm creating a new Prism4 application with MEF and it works nice. I've created the Shell, etc and everything is OK.
But now I need to create a new Window with a Region inside it but it seems like the region is not registered with the RegionManager (see the Window_Closing event) and the Region in the window work well because the views injected into it are shown.
Here's the code for the new Window
Wizard.xaml
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
<Button Content="_Previous" Margin="0, 0, 10, 0" />
<Button Content="_Next" />
</StackPanel>
<ContentControl cal:RegionManager.RegionName="WizardStepsRegion" />
</DockPanel>
When I try to get the window's Region I get the following exception "KeyNotFoundException was unhandled by user code", "The region manager does not contain the WizardStepsRegion region."
Wizard.xaml.cs
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
object asdf = regionManager.Regions["WizardStepsRegion"];
}
Why the region is not registered in the region manager?
Can someone help me?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在尝试创建一个对话框。您是导入该对话框还是使用
new Wizard()
创建它?如果您使用 new 运算符创建它,RegionManager 将不会知道任何信息。您可以使用 SetRegionManager。然后,RegionManager 将了解有关您的类型的所有信息,发现其区域等。另一个选项是导入向导类型,并在需要时仅
.Show()
它,但有时这不切实际。It sounds like you are trying to create a dialog. Are you Importing that dialog or creating it with
new Wizard()
? If you are creating it with thenew
operator, the RegionManager won't know anything about it. You can manually tell the RegionManager about the window using SetRegionManager.Then the RegionManager will know all about your type, discover its regions, etc. The other option is to Import the Wizard type and just
.Show()
it when you want, but sometimes this isn't practical.