我正在编写一个应用程序,我想在其中放置导航。此应用程序使用 WPF,我使用的是 Prism 7.2.0.1367。
所以我创建了 2 个视图:一个HomePage
和一个ModeFileAttente
视图。
我也在使用 MVVM 模式。
这是我的app.xaml.cs
:
public partial class App : PrismApplication
{
protected override Window CreateShell()
{
return Container.Resolve<V.HomePage>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialog<V.HomePage, VM.HomePageViewModel>();
containerRegistry.RegisterDialog<V.ModeFileAttente, VM.ModeFIleAttenteViewModel>();
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<Bootstrapper>();
}
}
我的HomePage.xaml
:
<Window x:Class="TestWPF.View.HomePage"
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="HomePage" Height="347.667" Width="664">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="277*"/>
<ColumnDefinition Width="16*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.ColumnSpan="2" Margin="0,0,0.333,-0.333">
<Button Padding="0" DockPanel.Dock="Left" Content="Mode normal" Command="{Binding ClickCommand}" CommandParameter="ModeFileAttente"/>
<Button Padding="0" DockPanel.Dock="Right" Content="Mode tournois" HorizontalAlignment="Stretch"/>
</DockPanel>
<ContentControl prism:RegionManager.RegionName="ContentRegion" Margin="5" />
</Grid>
</Window>
这是视图模型:
class HomePageViewModel : BindableBase, IDialogAware, INotifyPropertyChanged
{
#region Private region
private readonly IRegionManager _regionManager;
public event Action<IDialogResult> RequestClose;
#endregion
public DelegateCommand<string> ClickCommand { get; private set; }
public string Title => throw new NotImplementedException();
public HomePageViewModel(IRegionManager regionManager)
{
_regionManager = regionManager;
ClickCommand = new DelegateCommand<string>(ExecuteClickCommand);
}
private void ExecuteClickCommand(string path) {
_regionManager.RequestNavigate("ContentRegion", "FileAttente");
}
public bool CanCloseDialog()
{
throw new NotImplementedException();
}
public void OnDialogClosed()
{
throw new NotImplementedException();
}
public void OnDialogOpened(IDialogParameters parameters)
{
throw new NotImplementedException();
}
}
我也有一Bootstrapper
堂课:
public class Bootstrapper : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<ModeFileAttente>();
}
}
我的 MVVM 模式运行良好,但是当我想在“主页”和“ModeFileAttente”视图之间导航时,除了视图上的“System.Object”之外什么也没有发生。
我已经搜索了可能是什么问题,但我没有解决我的问题。
这个版本的棱镜还有人遇到这个错误吗?
PS:我的 2 视图位于“视图”文件夹中,与 ViewModel 文件夹中的视图模型相同