SagiK-Repository / POC_.Net_DevExpress

✔ [POC] .Net DevExpress를 분석합니다.
0 stars 0 forks source link

Splash Window #20

Closed SAgiKPJH closed 9 months ago

SAgiKPJH commented 9 months ago
SAgiKPJH commented 9 months ago

Code


public class SplashService : IDisposable
{
    private SplashScreenManager splashManager;
    private DXSplashScreenViewModel splashViewModel;
    private PredefinedSplashScreenType SplashScreenType { get; set; }

    #region public events
    public event EventHandler Starting;
    public event EventHandler Started;
    public event EventHandler Closing;
    public event EventHandler Closed;
    #endregion

    public SplashService(SplashScreenManager splashManager = null, DXSplashScreenViewModel splashViewModel = null, PredefinedSplashScreenType splashScreenType = PredefinedSplashScreenType.Fluent)
    {
        this.SplashScreenType = splashScreenType;
        this.splashViewModel = splashViewModel ?? SetDefaultViewModel();
        this.splashManager = splashManager ?? SetDefaultSplashScreenManager();
    }

    public DXSplashScreenViewModel SetDefaultViewModel()
    {
        bool isFluent = SplashScreenType.Equals(PredefinedSplashScreenType.Fluent);
        return new DXSplashScreenViewModel()
        {
            Logo = new Uri(String.Format(@"pack://application:,,,/DevExpress.Xpf.DemoBase.v{0};component/DemoLauncher/Images/Logo.svg", AssemblyInfo.VersionShort)),
            Status = "Starting...",
            Title = "Loading Screen",
            Subtitle = "Powered by Mirero",
            Copyright = AssemblyInfo.AssemblyCopyright + (AssemblyInfo.AssemblyCopyright.Contains("All rights reserved") ? "" : "\nAll rights reserved"),
            IsIndeterminate = true,
            Progress = 0
        };
    }
    public SplashScreenManager SetDefaultSplashScreenManager()
    {
        return SplashScreenType switch
        {
            PredefinedSplashScreenType.Fluent => SplashScreenManager.CreateFluent(splashViewModel, topmost: true),
            PredefinedSplashScreenType.Themed => SplashScreenManager.CreateThemed(splashViewModel, topmost: true),
            _ => SplashScreenManager.CreateWaitIndicator(splashViewModel, topmost: true),
        };
    }

    public async void Show(string status, int showDelay = 0, int minDuration = 500, WindowStartupLocation startupLocation = WindowStartupLocation.CenterOwner, bool trackOwnerPosition = true, InputBlockMode inputBlock = InputBlockMode.Window)
    {
        Starting?.Invoke(this, EventArgs.Empty);

        splashViewModel.Status = status;
        splashManager?.Show(showDelay, minDuration, null, startupLocation, trackOwnerPosition, inputBlock);

        Started?.Invoke(this, EventArgs.Empty);
    }

    public async void Close(int closeDelay = 0)
    {
        Closing?.Invoke(this, EventArgs.Empty);

        await Task.Delay(closeDelay);

        splashManager?.Close();

        Closed?.Invoke(this, EventArgs.Empty);
    }

    public void Dispose()
    {
        DisposeEventAsync(Starting);
        DisposeEventAsync(Started);
        DisposeEventAsync(Closing);
        DisposeEventAsync(Closed);
    }

    private void DisposeEventAsync(EventHandler eventHandler)
    {
        if (eventHandler != null)
            foreach (var handler in eventHandler.GetInvocationList())
                eventHandler -= (EventHandler)handler;
    }
}
SAgiKPJH commented 9 months ago

목적

화면 변경 중간에 대기화면 띄우기

필요한 동작

  1. Show
  2. Close
SAgiKPJH commented 9 months ago

사용법

1. View Show ~ Load 사이에 띄우기

splashService.Show("Please Wait...", minDuration:1000);

loginView.Loaded += (s, ev) => splashService.Close();
loginView.Show();
splashService.Show("Please Wait...");

mainView.IsVisibleChanged += (s, ev) => splashService.Close();
mainView.Show();


2. Splash 창 옵션


3. 창 종류 변경

splashService = new SplashService(splashScreenType:DevExpress.Xpf.Core.PredefinedSplashScreenType.Fluent);
splashService = new SplashService(splashScreenType:DevExpress.Xpf.Core.PredefinedSplashScreenType.WaitIndicator);
splashService = new SplashService(splashScreenType:DevExpress.Xpf.Core.PredefinedSplashScreenType.Themed);


SplashService 제공 Event

  public event EventHandler Starting;
  public event EventHandler Started;
  public event EventHandler Closing;
  public event EventHandler Closed;

Event 활용한 비동기 처리 가능


Custom Splash


참고 사이트