私は、プリズムと地域を使ってビューベースのナビゲーションを動作させようとしています。私はMSDNのドキュメントを調べてみましたが、何らかの理由でそれを動作させることができず、何が間違っているのか分かりません。だから、これは私がこれまでに得たものである:Wpf Prism Region Navigation
MainShellViewModel.cs
//Private Variables
private readonly IRegionManager _regionManager;
//Public Variables
public DelegateCommand<string> NavigateCommand { get; set; }
//Functions and Methods
public MainShellViewModel(IRegionManager regionManager)
{
//Region Manager
_regionManager = regionManager;
NavigateCommand = new DelegateCommand<string>(Navigate);
Initialize();
}
public void Initialize()
{
//Startup View
_regionManager.RegisterViewWithRegion("ViewMainFrame", typeof(Views.Dashboard));
}
public void Navigate(string uri)
{
//Navigation
if(uri != null)
{
_regionManager.RequestNavigate("ViewMainFrame", uri);
}
}
サイドノート:私は私はNavigateメソッドということで入れていた、その後多くのチュートリアルの一つ、私はそれが必要なのですか? MainShellViewModelを起動時に挿入されるメインビューとして使用しています。
DashboardViewModel.cs:私は私のコンテナ/ビューを登録した場合(エラーを含む)
{
//Private Variables
private bool _canExercise = true;
//Public Variables
public bool CanExercise()
{
return _canExercise;
}
RelayCommand _exerciseSelCommand;
public ICommand ExerciseSelCommand
{
get
{
if (_exerciseSelCommand == null)
_exerciseSelCommand = new RelayCommand(ExerciseSel, CanExercise);
return _exerciseSelCommand;
}
}
//Dashboard Functions and Methods
IRegion _regionManager;
private void ExerciseSel()
{
SoundPlayers.ButtonSound();
_regionManager.RequestNavigate(new Uri("ExerciseView", UriKind.Relative)); //This gives me the error, it says it can't be nullable?
}
ここでは、など
Bootstrapper.cs:
protected override void ConfigureContainer()
{
base.ConfigureContainer();
#region Region Register Zone
//register views here!
Container.RegisterType(typeof(object), typeof(Views.LoginView), "LoginView");
Container.RegisterType(typeof(object), typeof(Views.Dashboard), "Dashboard");
Container.RegisterType(typeof(object), typeof(Views.ExerciseView), "SettingsView");
Container.RegisterType(typeof(object), typeof(Views.ResultsView), "ResultsView");
Container.RegisterType(typeof(object), typeof(Views.UserCreationView), "UserCreationView");
#endregion
}
だから、基本的にはIダッシュボード(私の現在のスタートアップビュー)から、ボタンをクリックしてコンテナに登録されている他のビューにアクセスできるようにしたいだけです。
MainShell.xaml:
<Window x:Name="Shell"
x:Class="Equinox.Views.MainShell"
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"
mc:Ignorable="d"
xmlns:prism="http://www.codeplex.com/prism"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="Equinox"
FontFamily="Quicksand"
Height="900"
Width="1500"
SizeToContent="WidthAndHeight"
ResizeMode="CanResize"
Background="#EEF3F4"
WindowStyle="SingleBorderWindow"
Icon="/Equinox;component/favicon.ico"
WindowStartupLocation="CenterScreen">
<!-- Main View Region -->
<ContentControl x:Name="ContentControlMain"
prism:RegionManager.RegionName="ViewMainFrame"
Focusable="False"/>
しかし、私は私の領域は、別の見方を作るしようとすると、エラーが発生しておきます。私がやっていたやり方は、私のDashboardViewModelを使って、_regionManager
という別のIRegionManager
を作成し、RequestNavigationを実行することでした。私はそれを実行し、次のビューにリンクする必要があるボタンを押してまで、私はエラーを持っていません。
助けていただけたら幸いです!
ありがとうございます!
ダッシュボードのVMコードの関連部分、つまりIRegionManagerを作成する場所と、そのRequestNavigation()メソッドを呼び出す場所を表示できますか?また、表示されているエラーメッセージの詳細を提供できますか?(あなたがメインのVMで行うように)ただ、ダブルチェックに、あなたはあなたのダッシュボードVMにIRegionManagerを注入しなければならない、とIRegionManagerはあなたのブートストラップの*シングルトン*として登録する必要があります。 –
よろしくお願いします。私はちょうどそれを追加した。 xD – Hypergyzed