저는 프리즘과 지역을 사용하여보기 기반 탐색을 작동 시키려고했습니다. MSDN의 설명서를 살펴 보려고했지만 어떤 이유로 작동하지 못하고 잘못된 것을 알지 못합니다. 그래서 이것은 내가 지금까지 무엇을 가지고 있습니다 :Wpf 프리즘 지역 내비게이션
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);
}
}
사이드 노트 : 나는 나를 탐색 방법 있음을 넣어 한 다음에 많은 자습서 중 하나, 나는 그것을 필요합니까? 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에 IRegionManager를 주입해야하며 (기본 VM과 마찬가지로) 부트 스트 래퍼에 IRegionManager를 * 싱글 톤 *으로 등록해야합니다. –
네, 죄송합니다. 방금 추가했습니다. xD – Hypergyzed