여기에서 나오는 코드는 아래와 같은 기술을 사용하여 데이터를 전달하는 내용을 담고 있다.
- Event Aggregator 사용 : StudentListViewModel에서는 학생을 등록하고, TeacherListViewModel에서는 선생을 등록할 때 ClassRoomListViewModel에서 이 등록현황을 알린다.
- DialogParameters 사용 : ClassRoomListViewModel에서 새롭게 팝업 되는 ClassRoomWizardViewModel에게 학생과 선생 리스트를 파라미터로 전달한다.
1. Event Aggregator 사용하여 구독하기
1) 3개의 ViewModel 모두 IEventAggregator를 사용하며 생성자에서 인수로 받는다.
2) 구독해서 받은 데이터를 저장할 SubscriptionToken도 멤버변수로 받아준다.
3) PubSubEvent를 상속받는 DataChangedEvent와 DataChangedEvent2를 구현해 주는데 각각 자료형을 유의해준다.
4) StudentListViewModel과 TeacherListViewModel에서는 Publish()를 호출해주고 ClassRoomViewModel에서는 OnDataChanged()와 OnDataChanged2(0를 구현해 주고 Subscribe()를 호출해 준다.
5) 구독자인 ClassRoomListViewModel에서는 소멸자에 Unsubscribe()를 호출해 준다.
<ClassRoomListViewModel.cs>
using HelloSchool.Modules.Status.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Collections.ObjectModel;
using Prism.Events;
namespace HelloSchool.Modules.Status.Views.ClassRoomView
{
public class ClassRoomListViewModel : BindableBase, INavigationAware
{
private readonly IDialogService _dialogService;
private readonly IEventAggregator _eventAggregator;
private readonly SubscriptionToken _dataChangedToken;
private readonly SubscriptionToken _dataChangedToken2;
private ObservableCollection<ClassRoom> _classRooms = new ObservableCollection<ClassRoom>();
private ObservableCollection<Student> _students = new ObservableCollection<Student>();
private ObservableCollection<Teacher> _teachers = new ObservableCollection<Teacher>();
public ObservableCollection<ClassRoom> ClassRooms
{
get { return _classRooms; }
set { SetProperty(ref _classRooms, value); }
}
public ObservableCollection<Student> Students
{
get { return _students; }
set { SetProperty(ref _students, value); }
}
public ObservableCollection<Teacher> Teachers
{
get { return _teachers; }
set { SetProperty(ref _teachers, value); }
}
public ClassRoomListViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
{
_dialogService = dialogService;
_eventAggregator = eventAggregator;
AddClassRoomCommand = new DelegateCommand(AddClassRoom);
_dataChangedToken = _eventAggregator.GetEvent<DataChangedEvent>().Subscribe(OnDataChanged);
_dataChangedToken2 = _eventAggregator.GetEvent<DataChangedEvent2>().Subscribe(OnDataChanged2);
}
~ClassRoomListViewModel()
{
_eventAggregator.GetEvent<DataChangedEvent>().Unsubscribe(_dataChangedToken);
_eventAggregator.GetEvent<DataChangedEvent2>().Unsubscribe(_dataChangedToken2);
}
private void OnDataChanged(ObservableCollection<Student> inputStudents)
{
Students = inputStudents;
}
private void OnDataChanged2(ObservableCollection<Teacher> inputTeachers)
{
Teachers = inputTeachers;
}
public DelegateCommand AddClassRoomCommand { get; private set; }
public DelegateCommand<ClassRoom> EditClassRoomCommand { get; private set; }
public DelegateCommand<ClassRoom> RemoveClassRoomCommand { get; private set; }
private void AddClassRoom()
{
var parameters = new DialogParameters();
parameters.Add("tmpStudents", Students);
parameters.Add("tmpTeachers", Teachers);
_dialogService.ShowDialog("ClassRoomWizard", parameters, r =>
{
if (r.Result == ButtonResult.OK)
{
ClassRoom classRoom = r.Parameters.GetValue<ClassRoom>("classRoom");
ClassRooms.Add(classRoom);
}
RaisePropertyChanged("ClassRooms");
});
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
}
<ClassRoomList.xaml>
<UserControl x:Class="HelloSchool.Modules.Status.Views.ClassRoomView.ClassRoomList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/HelloSchool.Modules.Status;component/Views/ClassRoomView/ClassRoomListResource.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<DockPanel VerticalAlignment="Top" Margin="0,0,0,10">
<TextBlock Text="반 관리"/>
<Button DockPanel.Dock="Right" Command="{Binding AddClassRoomCommand}" ToolTip="반 등록" FontSize="20" Content="반 등록" Foreground="Blue" />
<Rectangle Fill="Transparent"></Rectangle>
</DockPanel>
</Grid>
</UserControl>
<StudentListViewModel.cs>
using Prism.Mvvm;
using System.Collections.ObjectModel;
using HelloSchool.Modules.Status.Models;
using Prism.Regions;
using Prism.Services.Dialogs;
using Prism.Commands;
using System.Printing;
using Prism.Events;
namespace HelloSchool.Modules.Status.Views.StudentView
{
public class StudentListViewModel : BindableBase, INavigationAware
{
private readonly IDialogService _dialogService;
private readonly IEventAggregator _eventAggregator;
private ObservableCollection<Student> _students = new ObservableCollection<Student>();
public ObservableCollection<Student> Students
{
get { return _students; }
set { SetProperty(ref _students, value); }
}
public StudentListViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
{
_dialogService = dialogService;
AddStudentCommand = new DelegateCommand(AddStudent);
EditStudentCommand = new DelegateCommand<Student>(EditStudent);
RemoveStudentCommand = new DelegateCommand<Student>(RemoveStudent);
_eventAggregator = eventAggregator;
}
public DelegateCommand AddStudentCommand { get; private set; }
public DelegateCommand<Student> EditStudentCommand { get; private set; }
public DelegateCommand<Student> RemoveStudentCommand { get; private set; }
public void OnNavigatedTo(NavigationContext navigationContext)
{
var students = navigationContext.Parameters["students"] as ObservableCollection<Student>;
if (students != null)
Students = students;
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
private void AddStudent()
{
_dialogService.ShowDialog("StudentWizard", r =>
{
if (r.Result == ButtonResult.OK)
{
Student student = r.Parameters.GetValue<Student>("student");
Students.Add(student);
}
RaisePropertyChanged("Students");
_eventAggregator.GetEvent<DataChangedEvent>().Publish(Students);
});
}
private void EditStudent(Student student)
{
ObservableCollection<Student> students = Students;
int idx = students.IndexOf(student);
DialogParameters parameters = new DialogParameters();
parameters.Add("student", student.Clone());
_dialogService.ShowDialog("StudentWizard", parameters, r =>
{
if (r.Result == ButtonResult.OK)
{
Student editStudent = r.Parameters.GetValue<Student>("student");
Students.Remove(student);
Students.Insert(idx, editStudent);
RaisePropertyChanged("Students");
}
});
}
private void RemoveStudent(Student student)
{
Students.Remove(student);
}
public int TotalSize
{
get { return Students.Count;}
}
}
}
<TeacherListViewModel.cs>
using Prism.Mvvm;
using System.Collections.ObjectModel;
using HelloSchool.Modules.Status.Models;
using Prism.Regions;
using Prism.Services.Dialogs;
using Prism.Commands;
using Prism.Events;
namespace HelloSchool.Modules.Status.Views.TeacherView
{
public class TeacherListViewModel : BindableBase, INavigationAware
{
private readonly IDialogService _dialogService;
private readonly IEventAggregator _eventAggregator;
private ObservableCollection<Teacher> _teachers = new ObservableCollection<Teacher>();
public ObservableCollection<Teacher> Teachers
{
get { return _teachers; }
set { SetProperty(ref _teachers, value); }
}
public TeacherListViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
{
_dialogService = dialogService;
AddTeacherCommand = new DelegateCommand(AddTeacher);
EditTeacherCommand = new DelegateCommand<Teacher>(EditTeacher);
RemoveTeacherCommand = new DelegateCommand<Teacher>(RemoveTeacher);
_eventAggregator = eventAggregator;
}
public DelegateCommand AddTeacherCommand { get; private set; }
public DelegateCommand<Teacher> EditTeacherCommand { get; private set; }
public DelegateCommand<Teacher> RemoveTeacherCommand { get; private set; }
public void OnNavigatedTo(NavigationContext navigationContext)
{
var teachers = navigationContext.Parameters["teachers"] as ObservableCollection<Teacher>;
if (teachers != null)
Teachers = teachers;
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
private void AddTeacher()
{
_dialogService.ShowDialog("TeacherWizard", r =>
{
if (r.Result == ButtonResult.OK)
{
Teacher teacher = r.Parameters.GetValue<Teacher>("teacher");
Teachers.Add(teacher);
}
RaisePropertyChanged("Teachers");
_eventAggregator.GetEvent<DataChangedEvent2>().Publish(Teachers);
});
}
private void EditTeacher(Teacher teacher)
{
ObservableCollection<Teacher> teachers = Teachers;
int idx = teachers.IndexOf(teacher);
DialogParameters parameters = new DialogParameters();
parameters.Add("teacher", teacher.Clone());
_dialogService.ShowDialog("TeacherWizard", parameters, r =>
{
if (r.Result == ButtonResult.OK)
{
Teacher editTeacher = r.Parameters.GetValue<Teacher>("teacher");
Teachers.Remove(teacher);
Teachers.Insert(idx, editTeacher);
RaisePropertyChanged("Teachers");
}
});
}
private void RemoveTeacher(Teacher teacher)
{
Teachers.Remove(teacher);
}
public int TotalSize
{
get { return Teachers.Count; }
}
}
}
<DataChangedEvent.cs>
using HelloSchool.Modules.Status.Models;
using Prism.Events;
using System.Collections.ObjectModel;
namespace HelloSchool.Modules.Status.Views
{
public class DataChangedEvent : PubSubEvent<ObservableCollection<Student>>
{
}
}
<DataChangedEvent2.cs>
using HelloSchool.Modules.Status.Models;
using Prism.Events;
using System.Collections.ObjectModel;
namespace HelloSchool.Modules.Status.Views
{
public class DataChangedEvent2 : PubSubEvent<ObservableCollection<Teacher>>
{
}
}
2. DialogParameter를 사용하여 ViewModel 간 데이터 전달하기
1) ClassRoomListViewModel.cs에서 AddClassRoom() 함수를 보면 DialogParameters 변수를 생성하여 구독해서 갱신한 Students와 Teachers를 각각 Add 해주고 IDialogService.ShowDialog() 인수로 넘겨주는 것을 알 수 있다.
2) IWizardService : Dialog 간의 공유데이터인 Teachers와 Students 존재
3) IDialogParameters : ViewModel에서 Dialog로 파라미터를 사용하여 데이터 전달
4) StatusBarModule.cs : Student, Teacher, ClassRoom과 관련된 View를 Region에 등록
5) App.xaml.cs : moduleCatalog 추가 및 기본 prism에서 제시하는 네임스페이스 구조와 다르게 사용할 경우 COnfigureViewModelLocator() 재정의
<IWizardService.cs>
using HelloSchool.Modules.Status.Models;
using System.Collections.ObjectModel;
namespace HelloSchool.Modules.Status.Views.ClassRoomView.Wizard
{
public interface IWizardService
{
public ClassRoom ClassRoom { get; set; }
public ObservableCollection<Teacher> Teachers { get; set; }
public ObservableCollection<Student> Students { get; set; }
void Reset();
public bool GenerateClassRoom();
}
}
<WizardService.cs>
using HelloSchool.Modules.Status.Models;
using Prism.Mvvm;
using System;
using System.Collections.ObjectModel;
namespace HelloSchool.Modules.Status.Views.ClassRoomView.Wizard
{
public class WizardService : BindableBase, IWizardService
{
private ClassRoom _classRoom;
private ObservableCollection<Teacher> _teachers;
private ObservableCollection<Student> _students;
public WizardService()
{
}
public ClassRoom ClassRoom
{
get => _classRoom;
set { SetProperty(ref _classRoom, value); }
}
public ObservableCollection<Teacher> Teachers
{
get { return _teachers; }
set { SetProperty(ref _teachers, value); }
}
public ObservableCollection<Student> Students
{
get { return _students; }
set { SetProperty(ref _students, value); }
}
public bool GenerateClassRoom()
{
throw new NotImplementedException();
}
public void Reset()
{
_classRoom = new ClassRoom();
}
}
}
<ClassRoomWizardViewModel.cs>
using HelloSchool.Modules.Status.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace HelloSchool.Modules.Status.Views.ClassRoomView.Wizard
{
public class ClassRoomWizardViewModel : BindableBase, IDialogAware
{
private readonly IWizardService _wizardService;
private readonly IRegionManager _regionManager;
private string _title;
private bool _isLast = false;
private bool _canNext = true;
private bool _canPrev = false;
public event Action<IDialogResult> RequestClose;
public IDialogResult Result { get; set; }
public string Title
{
get { return _title; }
}
public bool IsLast
{
get { return _isLast; }
set { SetProperty(ref _isLast, value); }
}
public bool CanNext
{
get { return _canNext; }
set { SetProperty(ref _canNext, value); }
}
public bool CanPrev
{
get { return _canPrev; }
set { SetProperty(ref _canPrev, value); }
}
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
if (parameters.Count > 0)
{
_wizardService.Students = parameters.GetValue< ObservableCollection<Student> >("tmpStudents");
_wizardService.Teachers = parameters.GetValue<ObservableCollection<Teacher>>("tmpTeachers");
}
}
public ClassRoomWizardViewModel(IRegionManager regionManager, IWizardService wizardService)
{
_title = "반 등록";
_regionManager = regionManager;
_regionManager.RegisterViewWithRegion("ClassRoomWizardRegion", "TeacherRegister");
_wizardService = wizardService;
_wizardService.Reset();
ResizeCommand = new DelegateCommand(ResizeDialog);
MinimizeCommand = new DelegateCommand(MinimizeDialog);
CloseCommand = new DelegateCommand(CloseDialog);
FinishCommand = new DelegateCommand(FinishWizard);
}
public DelegateCommand ResizeCommand { get; private set; }
public DelegateCommand MinimizeCommand { get; private set; }
public DelegateCommand CloseCommand { get; private set; }
public DelegateCommand FinishCommand { get; private set; }
private void MinimizeDialog()
{
for (int i = 0; i < Application.Current.Windows.Count; i++)
{
if (Application.Current.Windows[i] is IDialogWindow)
Application.Current.Windows[i].WindowState = WindowState.Minimized;
}
}
private void ResizeDialog()
{
for (int i = 0; i < Application.Current.Windows.Count; i++)
{
if (Application.Current.Windows[i] is IDialogWindow)
{
if (Application.Current.Windows[i].WindowState != WindowState.Maximized)
Application.Current.Windows[i].WindowState = WindowState.Maximized;
else
Application.Current.Windows[i].WindowState = WindowState.Normal;
}
}
}
private void CloseDialog()
{
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
}
private void RaiseRequestClose(IDialogResult dialogResult)
{
RequestClose?.Invoke(dialogResult);
}
private void FinishWizard()
{
_regionManager.RequestNavigate("ClassRoomWizardRegion", "TeacherRegister");
if (!_wizardService.GenerateClassRoom())
{
}
DialogParameters parameters = new DialogParameters();
parameters.Add("classRoom", _wizardService.ClassRoom);
RaiseRequestClose(new DialogResult(ButtonResult.OK, parameters));
}
}
}
<ClassRoomWizard.xaml>
<UserControl x:Class="HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.ClassRoomWizard"
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"
xmlns:local="clr-namespace:HelloSchool.Modules.Status.Views.ClassRoomView.Wizard"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1200"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/HelloSchool.Modules.Status;component/Views/ClassRoomView/Wizard/ClassRoomWizardResource.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen"/>
<Setter Property="SizeToContent" Value="Manual"/>
<Setter Property="Width" Value="800"/>
<Setter Property="Height" Value="650"/>
</Style>
</prism:Dialog.WindowStyle>
<Grid Background="{StaticResource Wizard_2}">
<Grid.RowDefinitions>
<RowDefinition Height="22"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<DockPanel LastChildFill="True" Grid.Row="0" >
<TextBlock DockPanel.Dock="Left" Text="{Binding Title}" ></TextBlock>
<Button DockPanel.Dock="Right" Command="{Binding CloseCommand}" Content=""></Button>
<Button DockPanel.Dock="Right" Command="{Binding ResizeCommand}" Content=""></Button>
<Button DockPanel.Dock="Right" Command="{Binding MinimizeCommand}" Content=""></Button>
<Rectangle Fill="Transparent"></Rectangle>
</DockPanel>
<Grid Margin="20,5" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="115"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="1">
<ContentControl prism:RegionManager.RegionName="ClassRoomWizardRegion" />
</Border>
<Border Grid.Row="2">
<DockPanel LastChildFill="False" >
<Rectangle DockPanel.Dock="Top" Height="2" />
<Button DockPanel.Dock="Right" Content="완료" Command="{Binding FinishCommand}"/>
</DockPanel>
</Border>
</Grid>
</Grid>
</UserControl>
<TeacherRegisterViewModel.cs>
using HelloSchool.Modules.Status.Models;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.Pages
{
public class TeacherRegisterViewModel : BindableBase
{
private readonly IWizardService _wizardService;
public ObservableCollection<Teacher> Teachers
{
get { return _wizardService.Teachers; }
set { _wizardService.Teachers = value; }
}
public TeacherRegisterViewModel(IWizardService wizardService)
{
_wizardService = wizardService;
}
}
}
<TeacherRegister.xaml>
<UserControl x:Class="HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.Pages.TeacherRegister"
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"
xmlns:local="clr-namespace:HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.Pages"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1200" d:Background="White"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/HelloSchool.Modules.Status;component/Views/ClassRoomView/Wizard/ClassRoomWizardResource.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<ListBox ItemsSource="{Binding Teachers}"/>
</Grid>
</UserControl>
<StatusBarModule.cs>
using HelloSchool.Modules.Status.Views;
using HelloSchool.Modules.Status.Views.ClassRoomView;
using HelloSchool.Modules.Status.Views.ClassRoomView.Wizard;
using HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.Pages;
using HelloSchool.Modules.Status.Views.StudentView;
using HelloSchool.Modules.Status.Views.StudentView.Wizard;
using HelloSchool.Modules.Status.Views.StudentView.Wizard.Pages;
using HelloSchool.Modules.Status.Views.TeacherView;
using HelloSchool.Modules.Status.Views.TeacherView.Wizard;
using HelloSchool.Modules.Status.Views.TeacherView.Wizard.Pages;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace HelloSchool.Modules.Status
{
public class StatusBarModule : IModule
{
private readonly IRegionManager _regionManager;
public StatusBarModule(IRegionManager regionManager)
{
_regionManager = regionManager;
}
public void OnInitialized(IContainerProvider containerProvider)
{
_regionManager.RegisterViewWithRegion("ContentRegion", typeof(StudentList));
_regionManager.RegisterViewWithRegion("ContentRegion", typeof(TeacherList));
_regionManager.RegisterViewWithRegion("ContentRegion", typeof(ClassRoomList));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<StudentList, StudentListViewModel>();
containerRegistry.RegisterForNavigation<TeacherList, TeacherListViewModel>();
containerRegistry.RegisterForNavigation<ClassRoomList, ClassRoomListViewModel>();
containerRegistry.RegisterForNavigation<TeacherRegister, TeacherRegisterViewModel>();
containerRegistry.RegisterSingleton<HelloSchool.Modules.Status.Views.StudentView.Wizard.IWizardService, HelloSchool.Modules.Status.Views.StudentView.Wizard.WizardService>();
containerRegistry.RegisterSingleton<HelloSchool.Modules.Status.Views.TeacherView.Wizard.IWizardService, HelloSchool.Modules.Status.Views.TeacherView.Wizard.WizardService>();
containerRegistry.RegisterSingleton<HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.IWizardService, HelloSchool.Modules.Status.Views.ClassRoomView.Wizard.WizardService>();
containerRegistry.RegisterDialog<StudentWizard, StudentWizardViewModel>();
containerRegistry.RegisterDialog<TeacherWizard, TeacherWizardViewModel>();
containerRegistry.RegisterDialog<ClassRoomWizard, ClassRoomWizardViewModel>();
}
}
}
<App.xaml.cs>
using HelloSchool.Modules.ModuleName;
using HelloSchool.Modules.Status;
using HelloSchool.Modules.Status.Views;
using HelloSchool.Modules.Status.Views.ClassRoomView;
using HelloSchool.Modules.Status.Views.ClassRoomView.Wizard;
using HelloSchool.Modules.Status.Views.StudentView;
using HelloSchool.Modules.Status.Views.StudentView.Wizard;
using HelloSchool.Modules.Status.Views.StudentView.Wizard.Pages;
using HelloSchool.Modules.Status.Views.TeacherView;
using HelloSchool.Modules.Status.Views.TeacherView.Wizard;
using HelloSchool.Modules.Status.Views.TeacherView.Wizard.Pages;
using HelloSchool.Services;
using HelloSchool.Services.Interfaces;
using HelloSchool.ViewModels;
using HelloSchool.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Mvvm;
using System;
using System.Reflection;
using System.Windows;
namespace HelloSchool
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<MenuBarModule>();
moduleCatalog.AddModule<StatusBarModule>();
}
protected override void ConfigureViewModelLocator()
{
base.ConfigureViewModelLocator();
ViewModelLocationProvider.Register<MainWindow, MainWindowViewModel>();
ViewModelLocationProvider.Register<StudentList, StudentListViewModel>();
ViewModelLocationProvider.Register<TeacherList, TeacherListViewModel>();
ViewModelLocationProvider.Register<ClassRoomList, ClassRoomListViewModel>();
ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
{
var viewName = viewType.FullName;
var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
var viewModelName = $"{viewName}ViewModel, {viewAssemblyName}";
return Type.GetType(viewModelName);
});
}
}
}
'프로그래밍 > UWP | WPF' 카테고리의 다른 글
[WPF] Customized CheckBox 만들기 (0) | 2022.08.22 |
---|---|
[WPF] Pressed Button Style 만들기 (0) | 2022.08.19 |
[WPF] Window 이용한 Popup Dialog Alert Box 생성 (0) | 2022.08.19 |
[WPF] Circle gradient brush 설정하기 (1) | 2022.08.19 |
[WPF] Page 이용하여 초기화면 구성하기 (0) | 2022.08.11 |
댓글