■ IRegion 인터페이스를 사용해 수동으로 뷰 활성화하거나 비활성화하는 방법을 보여준다.
▶ ViewA.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<UserControl x:Class="TestProject.Views.ViewA" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> <Grid> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="36" Text="View A" /> </Grid> </UserControl> |
▶ ViewA.xaml.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 |
using System.Windows.Controls; namespace TestProject.Views { /// <summary> /// 뷰 A /// </summary> public partial class ViewA : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewA() /// <summary> /// 생성자 /// </summary> public ViewA() { InitializeComponent(); } #endregion } } |
▶ ViewB.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<UserControl x:Class="TestProject.Views.ViewB" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> <Grid> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="36" Text="View B" /> </Grid> </UserControl> |
▶ ViewB.xaml.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 |
using System.Windows.Controls; namespace TestProject.Views { /// <summary> /// 뷰 B /// </summary> public partial class ViewB : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewB() /// <summary> /// 생성자 /// </summary> public ViewB() { InitializeComponent(); } #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 |
<Window x:Class="TestProject.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://prismlibrary.com/" Width="800" Height="600" Title="IRegion 인터페이스 : 수동으로 뷰 활성화하기/비활성화하기" FontFamily="나눔고딕코딩" FontSize="16"> <DockPanel LastChildFill="True"> <StackPanel> <Button Content="Activate View A" Click="activateViewAButton_Click" /> <Button Content="Deactivate View A" Click="deactivateViewAButton_Click" /> <Button Content="Activate View B" Click="activateViewBButton_Click" /> <Button Content="Deactivate View B" Click="deactivateViewBButton_Click" /> </StackPanel> <ContentControl prism:RegionManager.RegionName="ContentRegion" HorizontalAlignment="Center" VerticalAlignment="Center" /> </DockPanel> </Window> |
▶ MainWindow.xaml.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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
using System.Windows; using Prism.Ioc; using Prism.Regions; using Unity; namespace TestProject.Views { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 컨테이너 확장 인터페이스 /// </summary> private IContainerExtension containerExtension; /// <summary> /// 영역 관리자 인터페이스 /// </summary> private IRegionManager regionManager; /// <summary> /// 영역 인터페이스 /// </summary> private IRegion region; /// <summary> /// 뷰 A /// </summary> private ViewA viewA; /// <summary> /// 뷰 B /// </summary> private ViewB viewB; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow(container, regionManager) /// <summary> /// 생성자 /// </summary> /// <param name="containerExtension">컨테이너 확장 인터페이스</param> /// <param name="regionManager">영역 관리자 인터페이스</param> public MainWindow(IContainerExtension containerExtension, IRegionManager regionManager) { InitializeComponent(); this.containerExtension = containerExtension; this.regionManager = regionManager; Loaded += Window_Loaded; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e) /// <summary> /// 윈도우 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Window_Loaded(object sender, RoutedEventArgs e) { this.viewA = this.containerExtension.Resolve<ViewA>(); this.viewB = this.containerExtension.Resolve<ViewB>(); this.region = this.regionManager.Regions["ContentRegion"]; this.region.Add(viewA); this.region.Add(viewB); } #endregion #region View A 활성화 버튼 클릭시 처리하기 - activateViewAButton_Click(sender, e) /// <summary> /// View A 활성화 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void activateViewAButton_Click(object sender, RoutedEventArgs e) { this.region.Activate(this.viewA); } #endregion #region View A 비활성화 버튼 클릭시 처리하기 - deactivateViewAButton_Click(sender, e) /// <summary> /// View A 비활성화 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void deactivateViewAButton_Click(object sender, RoutedEventArgs e) { this.region.Deactivate(this.viewA); } #endregion #region View B 활성화 버튼 클릭시 처리하기 - activateViewBButton_Click(sender, e) /// <summary> /// View B 활성화 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void activateViewBButton_Click(object sender, RoutedEventArgs e) { this.region.Activate(this.viewB); } #endregion #region View B 비활성화 버튼 클릭시 처리하기 - deactivateViewBButton_Click(sender, e) /// <summary> /// View B 비활성화 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void deactivateViewBButton_Click(object sender, RoutedEventArgs e) { this.region.Deactivate(this.viewB); } #endregion } } |
▶ MainApplication.xaml
1 2 3 4 5 6 7 |
<prism:PrismApplication x:Class="TestProject.MainApplication" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://prismlibrary.com/"> </prism:PrismApplication> |
▶ MainApplication.xaml.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 |
using System.Windows; using Prism.Ioc; using Prism.Unity; using TestProject.Views; namespace TestProject { /// <summary> /// 메인 애플리케이션 /// </summary> public partial class MainApplication : PrismApplication { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 쉘 생성하기 - CreateShell() /// <summary> /// 쉘 생성하기 /// </summary> /// <returns>쉘</returns> protected override Window CreateShell() { return Container.Resolve<MainWindow>(); } #endregion #region 타입 등록하기 - RegisterTypes(containerRegistry) /// <summary> /// 타입 등록하기 /// </summary> /// <param name="containerRegistry">컨테이너 레지스트리 인터페이스</param> protected override void RegisterTypes(IContainerRegistry containerRegistry) { } #endregion } } |