■ WindowedDocumentUIService 엘리먼트를 사용하는 방법을 보여준다.
▶ MainViewModel.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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Input; using DevExpress.Xpf.Mvvm; namespace HowToManageDocumentsViaWindowedDocumentUIService { /// <summary> /// 메인 뷰 모델 /// </summary> public class MainViewModel : ViewModelBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region Show Document Window 명령 - ShowDocumentWindowCommand /// <summary> /// Show Document Window 명령 /// </summary> public ICommand ShowDocumentWindowCommand { get; private set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 문서 관리자 서비스 - DocumentManagerService /// <summary> /// 문서 관리자 서비스 /// </summary> private IDocumentManagerService DocumentManagerService { get { return ServiceContainer.GetService<IDocumentManagerService>(); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainViewModel() /// <summary> /// 생성자 /// </summary> public MainViewModel() { ShowDocumentWindowCommand = new DelegateCommand<string>(OnShowDocumentWindowCommandExecute); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region Show Document Window 명령 실행시 처리하기 - OnShowDocumentWindowCommandExecute(documentName) /// <summary> /// Show Document Window 명령 실행시 처리하기 /// </summary> /// <param name="documentName">문서명</param> private void OnShowDocumentWindowCommandExecute(string documentName) { IDocument document = DocumentManagerService.CreateDocument(documentName, null, this); document.Title = documentName; document.DestroyOnClose = true; document.Show(); } #endregion } } |
▶ MainView.xaml
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 |
<UserControl x:Class="HowToManageDocumentsViaWindowedDocumentUIService.MainView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:HowToManageDocumentsViaWindowedDocumentUIService"> <UserControl.DataContext> <local:MainViewModel /> </UserControl.DataContext> <Grid> <StackPanel Orientation="Horizontal"> <Button Margin="10" Padding="5" FontSize="16" Command="{Binding ShowDocumentWindowCommand}" CommandParameter="Document1View" Content="Show Document1 Window" /> <Button Margin="10" Padding="5" FontSize="16" Command="{Binding ShowDocumentWindowCommand}" CommandParameter="Document2View" Content="Show Document3 Window" /> </StackPanel> </Grid> </UserControl> |
▶ 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 24 25 26 27 28 29 |
<Window x:Class="HowToManageDocumentsViaWindowedDocumentUIService.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" xmlns:local="clr-namespace:HowToManageDocumentsViaWindowedDocumentUIService" Title="HowToManageDocumentsViaWindowedDocumentUIService" Width="500" Height="300"> <Grid> <local:MainView HorizontalAlignment="Center" VerticalAlignment="Center"> <dxm:Interaction.Behaviors> <dx:WindowedDocumentUIService> <dx:HowToManageDocumentsViaWindowedDocumentUIService.WindowStyle> <Style TargetType="Window"> <Setter Property="Width" Value="400" /> <Setter Property="Height" Value="300" /> </Style> </dx:HowToManageDocumentsViaWindowedDocumentUIService.WindowStyle> </dx:WindowedDocumentUIService> </dxm:Interaction.Behaviors> </local:MainView> </Grid> </Window> |