첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ MainViewModel.cs

using System;
using System.Windows.Input;

using DevExpress.Xpf.Mvvm;

namespace HowToManageDocumentsViaCurrentWindowService
{
    /// <summary>
    /// 메인 뷰 모델
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region Close Window 명령 - CloseWindowCommand

        /// <summary>
        /// Close Window 명령
        /// </summary>
        public ICommand CloseWindowCommand { get; private set; }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 현재 윈도우 서비스 - CurrentWindowService

        /// <summary>
        /// 현재 윈도우 서비스
        /// </summary>
        private ICurrentWindowService CurrentWindowService
        {
            get
            {
                return ServiceContainer.GetService<ICurrentWindowService>();
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainViewModel()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainViewModel()
        {
            CloseWindowCommand = new DelegateCommand(OnCloseWindowCommandExecute);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Close Window 명령 실행시 처리하기 - OnCloseWindowCommandExecute()

        /// <summary>
        /// Close Window 명령 실행시 처리하기
        /// </summary>
        private void OnCloseWindowCommandExecute()
        {
            CurrentWindowService.Close();
        }

        #endregion
    }
}

 

728x90

 

▶ MainView.xaml

<UserControl
    x:Class="HowToManageDocumentsViaCurrentWindowService.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:local="clr-namespace:HowToManageDocumentsViaCurrentWindowService">
    <UserControl.DataContext>
        <local:MainViewModel />
    </UserControl.DataContext>
    <dxm:Interaction.Behaviors>
        <dxm:CurrentWindowService Window="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" />
    </dxm:Interaction.Behaviors>
    <Grid>
        <Button
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Padding="5"
            FontSize="16"
            Content="Close Window"
            Command="{Binding CloseWindowCommand}" />
    </Grid>
</UserControl>

 

300x250

 

▶ MainWindow.xaml

<Window
    x:Class="HowToManageDocumentsViaCurrentWindowService.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:HowToManageDocumentsViaCurrentWindowService"
    Title="CurrentWindowService"
    Width="600"
    Height="450">
    <Grid>
        <local:MainView />
    </Grid>
</Window>

 

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요