c# - WPF - Prism 7.1 - 导航 - 掌握选项卡控件 - 模态/对话框窗口
问题描述
我正在使用 Prism 7.1 导航框架 (WPF) 来使用以下配置弹出一个对话框窗口。这是成功的。但是,我希望此弹出窗口具有可以在其中来回导航的选项卡。当我单击弹出框上的按钮以尝试在其中显示 ViewA 时,没有任何反应。通过设置断点,我看到导航路径被命中,并且正在显示正确的视图名称。请参阅 PopUpWindow.cs。但是,当它解析视图时,视图不会显示。更糟糕的是,没有抛出错误!我很困惑为什么会发生这种情况。
假设我的命名空间是正确的,我做错了什么?
PrismApplication.cs
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<ViewA>();
}
//Have tried register type, register type for navigation, etc etc.
MainWindowViewModel.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Height="350" Width="525">
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding NotificationRequest}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" />
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
<StackPanel>
<Button Margin="5" Content="Raise Default Notification" Command="{Binding NotificationCommand}" />
</StackPanel>
MainWindowViewModel.cs
public MainWindowViewModel
{
public InteractionRequest<INotification> NotificationRequest { get; set; }
public DelegateCommand NotificationCommand { get; set; }
public MainWindowViewModel()
{
NotificationRequest = new InteractionRequest<INotification>();
NotificationCommand = new DelegateCommand(RaiseNotification);
}
void RaiseNotification()
{
NotificationRequest.Raise(new PopupWindow());
}
}
弹出窗口.xaml
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Height="350" Width="525">
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="5" >
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewA" Margin="5">Navigate to View A</Button>
</StackPanel>
<ContentControl prism:RegionManager.RegionName="ContentRegion" Margin="5" />
</DockPanel>
</UserControl>
弹出窗口.cs
public class PopupWindowViewModel
{
private readonly IRegionManager _regionManager;
public DelegateCommand<string> NavigateCommand { get; private set; }
public PopupWindowViewModel(IRegionManager regionManager)
{
_regionManager = regionManager;
NavigateCommand = new DelegateCommand<string>(Navigate);
}
private void Navigate(string navigatePath)
{
if (navigatePath != null)
_regionManager.RequestNavigate("ContentRegion", navigatePath);
//During debugging, this correctly shows navigatePath as "ViewA"
}
}
ViewA.xaml
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
<TextBlock Text="ViewA" FontSize="48" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</UserControl>
解决方案
也许只是没有找到你的观点。第二个参数不应该是 url 而不是字符串吗?从这里: https ://prismlibrary.github.io/docs/wpf/Navigation.html
IRegionManager regionManager = ...;
regionManager.RequestNavigate("MainRegion",
new Uri("InboxView", UriKind.Relative));
检查您的视图在哪里以及路径应该是什么。我认为你可以证明使用类似的东西:
var testinstance = System.Windows.Application.LoadComponent(testUrl);
如果您使用的是 MEF,我认为您还需要使用 Export 属性标记 View。
希望您的问题只是您忘记了文件夹或类似的东西。
如果不是,则可能与 regionmanager 未获得对您所在地区的引用有关。
推荐阅读
- vba - 使用 VBA 将时间从 UTC 转换为 PST/PDT/CET 和 CEST
- javascript - 如何使用 java 脚本在新选项卡中打开数组中的链接?
- android - E/FirebaseInstanceId:无法解析目标意图服务,跳过类名实施和错误:未找到 ServiceIntent
- c++ - 是否可以使用右值引用作为 pimpl 句柄?
- javascript - 图像预览在动态添加/删除文件上传字段中不起作用
- reactjs - 为活动按钮 ReactJS 添加一个类
- c++ - 折叠 std::initializer_list 的构造函数的参数列表与“正常”折叠
- javascript - 有没有办法轻松检查图片网址是否有效?
- json - 一种从 JSON 文件填充 Django 数据库的方法?
- javascript - JS / Node try catch (避免出错)