728x90
반응형
728x170
▶ MainViewModel.cs
using System.Windows.Input;
using DevExpress.Xpf.Mvvm;
namespace TestProject
{
/// <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="TestProject.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:TestProject">
<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="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestProject"
Width="800"
Height="600"
Title="CurrentWindowService 클래스 : 윈도우 닫기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<local:MainView />
</Grid>
</Window>
728x90
반응형
그리드형(광고전용)
'DevExpress > WPF' 카테고리의 다른 글
[DEVEXPRESS/WPF] 데이터 주석 적용하기 (0) | 2018.02.21 |
---|---|
[DEVEXPRESS/WPF] ICollectionView 인터페이스 : DXGrid 바인딩 하기 (0) | 2018.02.21 |
[DEVEXPRESS/WPF] 노드 반복자를 통해 노드를 반복하기 (0) | 2018.02.21 |
[DEVEXPRESS/WPF] TreeListView 클래스 : 동적으로 노드 로드하기 (0) | 2018.02.17 |
[DEVEXPRESS/WPF] 느슨하게 결합된 뷰 모델 사용하기 (0) | 2018.02.17 |
[DEVEXPRESS/WPF] BarManager 클래스 : BarSplitButtonItem 항목 생성하기 (0) | 2018.02.02 |
[DEVEXPRESS/WPF] BarManager 클래스 : BarStaticItem 항목 생성하기 (0) | 2018.02.02 |
[DEVEXPRESS/WPF] BarManager 클래스 : 에디터 내장하기 (0) | 2018.02.02 |
[DEVEXPRESS/WPF] WindowedDocumentUIService 클래스 : 문서 관리하기 (0) | 2018.01.31 |
[DEVEXPRESS/WPF] TabbedDocumentUIService 클래스 : 문서 관리하기 (0) | 2018.01.31 |
댓글을 달아 주세요