feat: WIP dialog window.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Media;
|
||||
|
||||
@@ -7,18 +8,46 @@ namespace Ursa.Controls;
|
||||
|
||||
public static class DialogBox
|
||||
{
|
||||
public static async Task ShowAsync()
|
||||
public static async Task<TResult?> ShowAsync<TView, TViewModel, TResult>(TViewModel vm) where TView : Control, new()
|
||||
{
|
||||
return;
|
||||
var window = new DialogWindow()
|
||||
{
|
||||
Content = new TView()
|
||||
{
|
||||
DataContext = vm,
|
||||
},
|
||||
DataContext = vm,
|
||||
};
|
||||
var lifetime = Application.Current?.ApplicationLifetime;
|
||||
if (lifetime is IClassicDesktopStyleApplicationLifetime classLifetime)
|
||||
{
|
||||
var main = classLifetime.MainWindow;
|
||||
if (main is null)
|
||||
{
|
||||
window.Show();
|
||||
return default(TResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await window.ShowDialog<TResult>(main);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(TResult);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ShowAsync<TView, TViewModel>(TViewModel vm)
|
||||
where TView: Control, new()
|
||||
where TViewModel: new()
|
||||
|
||||
public static async Task<TResult> ShowAsync<TView, TViewModel, TResult>(Window owner, TViewModel vm) where
|
||||
TView: Control, new()
|
||||
{
|
||||
TView t = new TView();
|
||||
t.DataContext = vm;
|
||||
var window = new DialogWindow();
|
||||
window.Content = new TView();
|
||||
window.DataContext = vm;
|
||||
return await window.ShowDialog<TResult>(owner);
|
||||
}
|
||||
|
||||
|
||||
public static async Task<object?> ShowOverlayAsync<TView, TViewModel>(TViewModel vm, string hostId)
|
||||
where TView : Control, new()
|
||||
|
||||
Reference in New Issue
Block a user