■ RegionAdapterBase<T> 클래스를 사용해 커스텀 영역 어댑터를 생성하는 방법을 보여준다.
▶ StackPanelRegionAdapter.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 |
using System.Collections.Specialized; using System.Windows; using System.Windows.Controls; using Prism.Regions; namespace TestProject { /// <summary> /// 스택 패널 영역 어댑터 /// </summary> public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel> { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - StackPanelRegionAdapter(regionBehaviorFactory) /// <summary> /// 생성자 /// </summary> /// <param name="regionBehaviorFactory">영역 BEHAVIOR 팩토리 인터페이스</param> public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 채택하기 - Adapt(region, regionTarget) /// <summary> /// 채택하기 /// </summary> /// <param name="region">영역</param> /// <param name="regionTarget">영역 타겟</param> protected override void Adapt(IRegion region, StackPanel regionTarget) { region.Views.CollectionChanged += (s, e) => { if(e.Action == NotifyCollectionChangedAction.Add) { foreach(FrameworkElement element in e.NewItems) { regionTarget.Children.Add(element); } } }; } #endregion #region 영역 생성하기 - CreateRegion() /// <summary> /// 영역 생성하기 /// </summary> /// <returns>영역 인터페이스</returns> protected override IRegion CreateRegion() { return new AllActiveRegion(); } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<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="RegionAdapterBase<T> 클래스 : 커스텀 영역 어댑터 생성하기"> <Grid> <StackPanel prism:RegionManager.RegionName="ContentRegion" /> </Grid> </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 |
using System.Windows; namespace TestProject.Views { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
using System.Windows; using System.Windows.Controls; using Prism.Ioc; using Prism.Regions; 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 #region 영역 어댑터 매핑 구성하기 - ConfigureRegionAdapterMappings(regionAdapterMappings) /// <summary> /// 영역 어댑터 매핑 구성하기 /// </summary> /// <param name="regionAdapterMappings">영업 어댑터 매핑</param> protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings) { base.ConfigureRegionAdapterMappings(regionAdapterMappings); regionAdapterMappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>()); } #endregion } } |