update
This commit is contained in:
@@ -1,33 +1,80 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using DialogHostAvalonia;
|
||||
using MsBox.Avalonia.ViewModels;
|
||||
|
||||
namespace Pilz.UI.AvaloniaUI.Dialogs;
|
||||
|
||||
public partial class AvaloniaFlyoutBase
|
||||
{
|
||||
// public static void Show<T>(Control controlToAssociate, object? tag = null)
|
||||
// {
|
||||
// Show<T>(controlToAssociate, null, null, tag: tag);
|
||||
// }
|
||||
//
|
||||
// public static void Show<T>(Control controlToAssociate, string? title, RadSvgImage? icon, object? tag = null)
|
||||
// {
|
||||
// Show(controlToAssociate, typeof(T), title, icon, tag: tag);
|
||||
// }
|
||||
//
|
||||
// public static void Show(Control controlToAssociate, Type flyoutContentType, string? title, RadSvgImage? icon, object? tag = null)
|
||||
// {
|
||||
// tagToAssign = tag;
|
||||
// titleToAssing = title;
|
||||
// iconToAssign = icon;
|
||||
// ParentContext = controlToAssociate;
|
||||
// CloseFlyout(); // Ensure it's closed!
|
||||
// RadFlyoutManager.Show(controlToAssociate, flyoutContentType);
|
||||
// }
|
||||
//
|
||||
// protected static void CloseFlyout()
|
||||
// {
|
||||
// if (typeof(RadFlyoutManager).GetField("flyoutInstance", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null) is FlyoutScreen instance
|
||||
// && instance.IsActive)
|
||||
// RadFlyoutManager.Close();
|
||||
// }
|
||||
public static void Show<T>(ContentControl owner, string? title, IImage? icon, object? tag = null) where T : AvaloniaFlyoutBase
|
||||
{
|
||||
Show(t, owner, title, icon);
|
||||
}
|
||||
|
||||
public static void Showy<T>(T content, ContentControl owner, string? title, IImage? icon) where T : AvaloniaFlyoutBase
|
||||
{
|
||||
Show(t, owner, title, icon);
|
||||
}
|
||||
|
||||
public async static Task<T> Show<T>(T content, ContentControl owner) where T : AvaloniaFlyoutBase
|
||||
{
|
||||
// Add styles
|
||||
DialogHostStyles? style = null;
|
||||
if (!owner.Styles.OfType<DialogHostStyles>().Any())
|
||||
{
|
||||
style = [];
|
||||
owner.Styles.Add(style);
|
||||
}
|
||||
|
||||
// Prepair content
|
||||
var parentContent = owner.Content;
|
||||
var dh = new DialogHost
|
||||
{
|
||||
Identifier = "FlyoutDialogIdentifier" + Guid.NewGuid()
|
||||
};
|
||||
owner.Content = null;
|
||||
dh.Content = parentContent;
|
||||
dh.CloseOnClickAway = content.CancelButtonVisible;
|
||||
dh.CloseOnClickAwayParameter = "FlyoutDialogIdentifier_Cancel";
|
||||
dh.DialogClosing += (ss, ee) =>
|
||||
{
|
||||
if (ee.Parameter?.ToString() == "FlyoutDialogIdentifier_Cancel")
|
||||
content.Close(null);
|
||||
};
|
||||
content.OnClose += (s, e) =>
|
||||
{
|
||||
// ...
|
||||
};
|
||||
owner.Content = dh;
|
||||
|
||||
// Handle close
|
||||
var tcs = new TaskCompletionSource<T>();
|
||||
content.SetCloseAction(() =>
|
||||
{
|
||||
var r = content.GetButtonResult();
|
||||
|
||||
if (dh.CurrentSession != null && dh.CurrentSession.IsEnded == false)
|
||||
{
|
||||
DialogHost.Close(dh.Identifier);
|
||||
}
|
||||
|
||||
owner.Content = null;
|
||||
dh.Content = null;
|
||||
owner.Content = parentContent;
|
||||
if (style != null)
|
||||
{
|
||||
owner.Styles.Remove(style);
|
||||
}
|
||||
tcs.TrySetResult(r);
|
||||
});
|
||||
|
||||
// Show dialog
|
||||
await DialogHost.Show(content, dh.Identifier);
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user