Skip to content

Commit

Permalink
Add messagebox to WindowManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed May 7, 2024
1 parent e2c0fd1 commit bd5c487
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Src/Denovo/Services/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Denovo.Models;
using Denovo.ViewModels;
using System.Threading.Tasks;

Expand All @@ -14,6 +15,7 @@ namespace Denovo.Services
public interface IWindowManager
{
Task ShowDialog(VmWithSizeBase vm);
Task<MessageBoxResult> ShowMessageBox(MessageBoxType mbType, string message);
}


Expand All @@ -36,5 +38,24 @@ public Task ShowDialog(VmWithSizeBase vm)
var lf = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime;
return win.ShowDialog(lf.MainWindow);
}

public async Task<MessageBoxResult> ShowMessageBox(MessageBoxType mbType, string message)
{
MessageBoxViewModel vm = new(mbType, message);
Window win = new()
{
Content = vm,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
CanResize = false,
SizeToContent = SizeToContent.WidthAndHeight,
Title = "Warning!",
};
vm.CLoseEvent += (s, e) => win.Close();

var lf = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime;
await win.ShowDialog(lf.MainWindow);

return vm.Result;
}
}
}

0 comments on commit bd5c487

Please sign in to comment.