■ DXSplashScreenService 클래스를 사용해 스플래시 화면을 표시하는 방법을 보여준다.
▶ SplashScreenWindow.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 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 84 85 86 87 88 89 90 |
<Window x:Name="splashWindow" x:Class="TestProject.SplashScreenWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ShowInTaskbar="False" Topmost="True" WindowStyle="None" ResizeMode="NoResize" Width="800" Height="600" AllowsTransparency="True" Background="Transparent"> <Window.Triggers> <EventTrigger RoutedEvent="Window.Unloaded"> <BeginStoryboard> <Storyboard x:Name="storyboard"> <DoubleAnimation Storyboard.TargetName="splashWindow" Storyboard.TargetProperty="Opacity" From="1.0" To="0" Duration="0:0:0.5" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Window.Triggers> <Grid x:Name="layoutGrid"> <Grid x:Name="splashGrid" HorizontalAlignment="Center" VerticalAlignment="Top" Width="450" Margin="0 100 0 0"> <Grid x:Name="shadowGrid" Margin="-10 -10 -10 -11"> <Grid.Background> <ImageBrush ImageSource="Images/shadow.png" /> </Grid.Background> </Grid> <Grid x:Name="backGrid"> <Border Background="Black" CornerRadius="3" Opacity="0.15" /> <Border Margin="1" CornerRadius="2" Background="White" /> </Grid> <Grid x:Name="contentGrid" Margin="12"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Image x:Name="mainImage" Source="Images/main.png" Stretch="None" /> <TextBlock x:Name="messageTextBlock" Grid.Row="1" Margin="0 12 0 0" Foreground="#ff2d2d2d" TextWrapping="Wrap" Text="DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio. Whether using WPF, Silverlight, ASP.NET or WinForms, DevExpress tools help you build and deliver your best in the shortest time possible." /> <ProgressBar x:Name="progressBar" Grid.Row="2" Margin="32 12" Height="12" /> <DockPanel x:Name="footerDockPanel" Grid.Row="3" Margin="0 12 0 0"> <TextBlock x:Name="footerTextBlock" HorizontalAlignment="Left" VerticalAlignment="Bottom" Opacity="0.5" Foreground="#ff2d2d2d" TextWrapping="Wrap" Text="Copyright © 1998-2013 Developer Express Inc." /> <Image x:Name="logoImage" DockPanel.Dock="Right" HorizontalAlignment="Right" Stretch="None" Source="Images/logo.png" /> </DockPanel> </Grid> </Grid> </Grid> </Window> |
▶ SplashScreenWindow.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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
using System; using System.Windows; using DevExpress.Xpf.Core; namespace TestProject { /// <summary> /// 스플래시 /// </summary> public partial class SplashScreenWindow : Window, ISplashScreen { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SplashScreenWindow() /// <summary> /// 생성자 /// </summary> public SplashScreenWindow() { InitializeComponent(); this.storyboard.Completed += storyboard_Completed; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region (ISplashScreen) 진행하기 - Progress(value) /// <summary> /// 진행하기 /// </summary> /// <param name="value">값</param> public void Progress(double value) { this.progressBar.Value = value; } #endregion #region (ISplashScreen) 스플래시 화면 닫기 - CloseSplashScreen() /// <summary> /// 스플래시 화면 닫기 /// </summary> public void CloseSplashScreen() { this.storyboard.Begin(this); } #endregion #region (ISplashScreen) 진행 상태 설정하기 - SetProgressState(isIndeterminate) /// <summary> /// 진행 상태 설정하기 /// </summary> /// <param name="isIndeterminate">미결정 여부</param> public void SetProgressState(bool isIndeterminate) { this.progressBar.IsIndeterminate = isIndeterminate; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 스토리 보드 완료시 처리하기 - storyboard_Completed(sender, e) /// <summary> /// 스토리 보드 완료시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void storyboard_Completed(object sender, EventArgs e) { this.storyboard.Completed -= storyboard_Completed; Close(); } #endregion } } |
▶ 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 |
using System; using System.Threading; using System.Windows.Input; using DevExpress.Xpf.Mvvm; namespace TestProject { /// <summary> /// 메인 뷰 모델 /// </summary> public class MainViewModel : ViewModelBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region Show Splash Screen 명령 - ShowSplashScreenCommand /// <summary> /// Show Splash Screen 명령 /// </summary> public ICommand ShowSplashScreenCommand { get; private set; } #endregion #region 스플래시 화면 서비스 - SplashScreenService /// <summary> /// 스플래시 화면 서비스 /// </summary> ISplashScreenService SplashScreenService { get { return GetService<ISplashScreenService>(); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainViewModel() /// <summary> /// 생성자 /// </summary> public MainViewModel() { ShowSplashScreenCommand = new DelegateCommand(OnShowSplashScreenCommandExecute); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region Show Splash Screen 명령 실행시 처리하기 - OnShowSplashScreenCommandExecute() /// <summary> /// Show Splash Screen 명령 실행시 처리하기 /// </summary> private void OnShowSplashScreenCommandExecute() { if(!SplashScreenService.IsSplashScreenActive) { SplashScreenService.ShowSplashScreen(); Thread.Sleep(TimeSpan.FromSeconds(3)); SplashScreenService.HideSplashScreen(); } } #endregion } } |
▶ 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="TestProject.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:TestProject" Width="800" Height="600" Title="DXSplashScreenService를 통해 스플래시 화면 보여주기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.DataContext> <local:MainViewModel /> </Window.DataContext> <dxm:Interaction.Behaviors> <dx:DXSplashScreenService SplashScreenType="{x:Type local:SplashScreenWindow}" /> </dxm:Interaction.Behaviors> <Grid> <Button HorizontalAlignment="Center" VerticalAlignment="Center" Padding="5" FontSize="16" Content="Show Splash Screen" Command="{Binding ShowSplashScreenCommand}" /> </Grid> </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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion } } |