■ IModuleManager 클래스의 LoadModule 메소드를 사용해 수동으로 모듈을 로드하는 방법을 보여준다.
[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 프로젝트]
▶ App.config
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> </startup> </configuration> |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<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="IModuleManager 클래스 : LoadModule 메소드를 사용해 수동으로 모듈 로드하기" FontFamily="나눔고딕코딩" FontSize="16"> <DockPanel LastChildFill="True"> <Button DockPanel.Dock="Top" Padding="5" Content="모듈 로드하기" Click="button_Click" /> <ContentControl prism:RegionManager.RegionName="ContentRegion" /> </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 |
using System.Windows; using Prism.Modularity; namespace TestProject.Views { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 모듈 관리자 /// </summary> private IModuleManager moduleManager; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow(moduleManager) /// <summary> /// 생성자 /// </summary> /// <param name="moduleManager">모듈 관리자 인터페이스</param> public MainWindow(IModuleManager moduleManager) { InitializeComponent(); this.moduleManager = moduleManager; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// M<e ////////////////////////////////////////////////////////////////////////////////////////// Public #region 버튼 클릭시 처리하기 - button_Click(sender, e) /// <summary> /// 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void button_Click(object sender, RoutedEventArgs e) { this.moduleManager.LoadModule("TestLibraryModule"); } #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 61 62 63 64 65 66 67 68 |
using System.Windows; using Prism.Ioc; using Prism.Modularity; using Prism.Unity; using TestLibrary; 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 모듈 카탈로그 구성하기 - ConfigureModuleCatalog(moduleCatalog) /// <summary> /// 모듈 카탈로그 구성하기 /// </summary> /// <param name="moduleCatalog">모듈 카탈로그 인터페이스</param> protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { Type moduleType = typeof(TestLibraryModule); moduleCatalog.AddModule ( new ModuleInfo() { ModuleName = moduleType.Name, ModuleType = moduleType.AssemblyQualifiedName, InitializationMode = InitializationMode.OnDemand } ); } #endregion } } |