Closed SAgiKPJH closed 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;
}
}
화면 변경 중간에 대기화면 띄우기
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();
splashService.Show("Please Wait...", showDelay:1000); // 1초 뒤 Show
splashService.Show("Please Wait...", minDuration:1000);
splashService.Show("Please Wait...", minDuration:2000);
splashService.Close(closeDelay:1000); // 1초 뒤 Close
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);
public event EventHandler Starting;
public event EventHandler Started;
public event EventHandler Closing;
public event EventHandler Closed;
Event 활용한 비동기 처리 가능