[C#/WPF/PRISM] PrismApplication 클래스 : 코드로 모듈 로드하기
■ PrismApplication 클래스를 사용해 코드로 모듈을 로드하는 방법을 보여준다. [TestLibrary 프로젝트] ▶ ViewA.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<UserControl x:Class="TestLibrary.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 TestLibrary.Views { /// <summary> /// View A /// </summary> public partial class ViewA : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewA() /// <summary> /// 생성자 /// </summary> public ViewA() { InitializeComponent(); } #endregion } } |
▶ TestLibraryModule.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 |
using Prism.Ioc; using Prism.Modularity; using Prism.Regions; using TestLibrary.Views; namespace TestLibrary { /// <summary> /// 테스트 라이브러리 모듈 /// </summary> public class TestLibraryModule : IModule { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 초기화시 처리하기 - OnInitialized(containerProvider) /// <summary> /// 초기화시 처리하기 /// </summary> /// <param name="containerProvider">컨테이너 공급자 인터페이스</param> public void OnInitialized(IContainerProvider containerProvider) { IRegionManager regionManager = containerProvider.Resolve<IRegionManager>(); regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA)); } #endregion #region 타입 등록하기 - RegisterTypes(containerRegistry) /// <summary> /// 타입 등록하기 /// </summary> /// <param name="containerRegistry">컨테이너 레지스트리 인터페이스</param> public void RegisterTypes(IContainerRegistry containerRegistry) { } #endregion } } |
[TestProject 프로젝트]