wpf - 如何在 Prism 中为我的对话窗口设置区域管理器?
问题描述
我在不使用 Shell 的情况下编写我的应用程序。所以我使用 IDialogService 创建了自己的 Window 并在我的一个模块中打开。就我而言,区域管理器附加到壳牌,但由于我没有它,当我尝试从一个视图导航到另一个视图时,区域管理器不起作用。
我知道 Region Navigation 在 shell 上运行良好(我对其进行了测试),当我用 IDialogService 替换 shell 时,相同的代码停止工作。
这是我所拥有的
<Window x:Class="TechDocs.Views.MainSettingsWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Title="MainSettingsWindow" Height="400" Width="750">
<Grid>
</Grid>
</Window>
第一个区域的内容。当我单击按钮时,它应该导航到第二个区域。
<UserControl x:Class="TechDocs.Views.SettingsView"
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:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Button Command="{Binding NodeSelectedCommand}" Name="Button"/>
<ContentControl prism:RegionManager.RegionName="region"/>
</Grid>
</UserControl>
在模块中,我将根窗口与保存第二个区域的按钮和内容控件的 UserControl 连接起来。
public class SettingsModule : IModule
{
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
var dialogService = _containerProvider.Resolve<IDialogService>();
containerRegistry.RegisterDialog<MainSettingsWindow>("MyWindow");
containerRegistry.RegisterDialog<SettingsView>("customView");
containerRegistry.RegisterForNavigation<MyView>();
dialogService.Show("customView");
}
}
当我单击按钮时,我会进入此代码
public void SelectedNode()
{
regionManager.RequestNavigate("region", "MyView");
}
RequestNavigate 没有给出任何异常,但屏幕上仍然没有出现任何异常。你能解释一下我应该如何在我的窗口中注册区域管理器吗?
解决方案
尝试使用以下静态方法在自定义窗口中显式初始化区域管理器:
RegionManager.SetRegionName(cc, "region");
RegionManager.SetRegionManager(cc, regionManager);
XAML:
<ContentControl x:Name="cc" prism:RegionManager.RegionName="region"/>
推荐阅读
- haskell - 当输入值是浮点类型而不是 Haskell 中的整数类型时如何创建错误消息
- php - 通过 AJAX 发送的数据在 $_POST 中不可用
- linux - 使用 bash 在 Linux 中的文件夹中查找拥有文件的所有用户
- python - 当我访问该视图时,未处理我的其中一个视图中的代码
- reactjs - 如何在反应中将来自json的数据与“this.props”连接起来
- php - 如何修复注意:未初始化的字符串偏移量:0
- python - 选择网格的所有顶点以分别访问每个顶点
- flutter - Mojave 10.14.4 更新后 ios-sim showdevicetypes 返回空
- typescript - 如何在 Angular 7 中分配公共变量(始终未定义)
- python - 在字典上使用 map lambda 打印 3 个值