■ FrameNavigationService 엘리먼트를 사용하는 방법을 보여준다.
▶ HomeViewModel.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
using System.Windows.Input; using DevExpress.Xpf.Mvvm; namespace TestProject { /// <summary> /// 홈 뷰 모델 /// </summary> public class HomeViewModel : ViewModelBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 상세 뷰 탐색 명령 - NavigateDetailViewCommand /// <summary> /// 상세 뷰 탐색 명령 /// </summary> public ICommand NavigateDetailViewCommand { get; private set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 탐색 서비스 - NavigationService /// <summary> /// 탐색 서비스 /// </summary> private INavigationService NavigationService { get { return ServiceContainer.GetService<INavigationService>(); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - HomeViewModel() /// <summary> /// 생성자 /// </summary> public HomeViewModel() { NavigateDetailViewCommand = new DelegateCommand(OnNavigateDetailViewCommandExecute); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 상세 뷰 탐색 명령 실행시 처리하기 - OnNavigateDetailViewCommandExecute() /// <summary> /// 상세 뷰 탐색 명령 실행시 처리하기 /// </summary> private void OnNavigateDetailViewCommandExecute() { NavigationService.Navigate("DetailView", null, this); } #endregion } } |
▶ HomeView.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<UserControl x:Class="TestProject.HomeView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:local="clr-namespace:FrameNavigationServiceApplication"> <UserControl.DataContext> <local:HomeViewModel /> </UserControl.DataContext> <Grid> <dxlc:TileLayoutControl> <dxlc:Tile Size="Small" Command="{Binding NavigateDetailViewCommand}"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Details" /> </dxlc:Tile> </dxlc:TileLayoutControl> </Grid> </UserControl> |
▶ DetailViewModel.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
using System.Windows.Input; using DevExpress.Xpf.Mvvm; namespace TestProject { /// <summary> /// 상세 뷰 모델 /// </summary> public class DetailViewModel : NavigationViewModelBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region Back 탐색 명령 - NavigateBackCommand /// <summary> /// Back 탐색 명령 /// </summary> public ICommand NavigateBackCommand { get; private set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 탐색 서비스 - NavigationService /// <summary> /// 탐색 서비스 /// </summary> private INavigationService NavigationService { get { return ServiceContainer.GetService<INavigationService>(); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DetailViewModel() /// <summary> /// 생성자 /// </summary> public DetailViewModel() { NavigateBackCommand = new DelegateCommand(OnNavigateBackCommandExecute, OnNavigateBackCommandCanExecute); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 탐색된 경우 처리하기 - OnNavigatedTo() /// <summary> /// 탐색된 경우 처리하기 /// </summary> protected override void OnNavigatedTo() { base.OnNavigatedTo(); (NavigateBackCommand as DelegateCommand).RaiseCanExecuteChanged(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region Back 탐색 명령 실행시 처리하기 - OnNavigateBackCommandExecute() /// <summary> /// Back 탐색 명령 실행시 처리하기 /// </summary> private void OnNavigateBackCommandExecute() { NavigationService.GoBack(); } #endregion #region Back 탐색 명령 실행 가능 여부 조사시 처리하기 - OnNavigateBackCommandCanExecute() /// <summary> /// Back 탐색 명령 실행 가능 여부 조사시 처리하기 /// </summary> /// <returns>Back 탐색 명령 실행 가능 여부</returns> private bool OnNavigateBackCommandCanExecute() { return NavigationService != null && NavigationService.CanGoBack; } #endregion } } |
▶ DetailView.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<UserControl x:Class="TestProject.DetailView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui" xmlns:local="clr-namespace:TestProject"> <UserControl.DataContext> <local:DetailViewModel /> </UserControl.DataContext> <Grid> <dxwui:PageAdornerControl Header="Details" Padding="10"> <Button Content="Back" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="75" Command="{Binding NavigateBackCommand}" /> </dxwui:PageAdornerControl> </Grid> </UserControl> |
▶ MainViewModel.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System.Windows.Input; using DevExpress.Xpf.Mvvm; namespace TestProject { /// <summary> /// 메인 뷰 모델 /// </summary> public class MainViewModel : ViewModelBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 윈도우 로드시 명령 - WindowLoadedCommand /// <summary> /// 윈도우 로드시 명령 /// </summary> public ICommand WindowLoadedCommand { get; private set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainViewModel() /// <summary> /// 생성자 /// </summary> public MainViewModel() { WindowLoadedCommand = new DelegateCommand(OnWindowLoadedCommandExecute); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 윈도우 로드시 명령 실행시 처리하기 - OnWindowLoadedCommandExecute() /// <summary> /// 윈도우 로드시 명령 실행시 처리하기 /// </summary> private void OnWindowLoadedCommandExecute() { ServiceContainer.GetService<INavigationService>().Navigate("HomeView", null, this); } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui" xmlns:dxwuin="http://schemas.devexpress.com/winfx/2008/xaml/windowsui/navigation" xmlns:local="clr-namespace:TestProject" Title="FrameNavigationService" Width="600" Height="450"> <Window.DataContext> <local:MainViewModel /> </Window.DataContext> <dxm:Interaction.Triggers> <dxm:EventToCommand EventName="Loaded" Command="{Binding WindowLoadedCommand}" /> </dxm:Interaction.Triggers> <dxm:Interaction.Behaviors> <dxwuin:FrameNavigationService Frame="{Binding ElementName=frame}" /> </dxm:Interaction.Behaviors> <Grid> <dxwui:NavigationFrame x:Name="frame" /> </Grid> </Window> |