This commit is contained in:
Pilzinsel64
2025-11-11 14:50:32 +01:00
parent 40b753062a
commit 593cdfb92c
3 changed files with 84 additions and 29 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
namespace Pilz.UI.AvaloniaUI.Dialogs; namespace Pilz.UI.AvaloniaUI.Dialogs;
@@ -26,14 +28,14 @@ public partial class AvaloniaDialogBase
return dialogPanel; return dialogPanel;
} }
private static T CreatePanelInstance<T>(object? tag) where T : AvaloniaFlyoutBase internal static T CreatePanelInstance<T>(object? tag) where T : AvaloniaFlyoutBase
{ {
var dialogPanel = Activator.CreateInstance<T>(); var dialogPanel = Activator.CreateInstance<T>();
dialogPanel.Tag = tag; dialogPanel.Tag = tag;
return dialogPanel; return dialogPanel;
} }
private static AvaloniaDialogBase CreateForm<T>(T dialogPanel, string? title, object? icon, WindowStartupLocation startPosition) where T : AvaloniaFlyoutBase internal static AvaloniaDialogBase CreateForm<T>(T dialogPanel, string? title, object? icon, WindowStartupLocation startPosition) where T : AvaloniaFlyoutBase
{ {
var dialog = new AvaloniaDialogBase var dialog = new AvaloniaDialogBase
{ {

View File

@@ -1,33 +1,80 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media;
using DialogHostAvalonia;
using MsBox.Avalonia.ViewModels;
namespace Pilz.UI.AvaloniaUI.Dialogs; namespace Pilz.UI.AvaloniaUI.Dialogs;
public partial class AvaloniaFlyoutBase public partial class AvaloniaFlyoutBase
{ {
// public static void Show<T>(Control controlToAssociate, object? tag = null) public static void Show<T>(ContentControl owner, string? title, IImage? icon, object? tag = null) where T : AvaloniaFlyoutBase
// { {
// Show<T>(controlToAssociate, null, null, tag: tag); Show(t, owner, title, icon);
// } }
//
// public static void Show<T>(Control controlToAssociate, string? title, RadSvgImage? icon, object? tag = null) public static void Showy<T>(T content, ContentControl owner, string? title, IImage? icon) where T : AvaloniaFlyoutBase
// { {
// Show(controlToAssociate, typeof(T), title, icon, tag: tag); Show(t, owner, title, icon);
// } }
//
// public static void Show(Control controlToAssociate, Type flyoutContentType, string? title, RadSvgImage? icon, object? tag = null) public async static Task<T> Show<T>(T content, ContentControl owner) where T : AvaloniaFlyoutBase
// { {
// tagToAssign = tag; // Add styles
// titleToAssing = title; DialogHostStyles? style = null;
// iconToAssign = icon; if (!owner.Styles.OfType<DialogHostStyles>().Any())
// ParentContext = controlToAssociate; {
// CloseFlyout(); // Ensure it's closed! style = [];
// RadFlyoutManager.Show(controlToAssociate, flyoutContentType); owner.Styles.Add(style);
// } }
//
// protected static void CloseFlyout() // Prepair content
// { var parentContent = owner.Content;
// if (typeof(RadFlyoutManager).GetField("flyoutInstance", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null) is FlyoutScreen instance var dh = new DialogHost
// && instance.IsActive) {
// RadFlyoutManager.Close(); 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;
}
} }

View File

@@ -1,3 +1,4 @@
using System;
using System.ComponentModel; using System.ComponentModel;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
@@ -168,10 +169,15 @@ public partial class AvaloniaFlyoutBase : UserControl
{ {
} }
protected void Close()
{
OnClose?.Invoke(this, EventArgs.Empty);
}
protected void Close(object? result) protected void Close(object? result)
{ {
Result = result; Result = result;
OnClose?.Invoke(this, EventArgs.Empty); Close();
} }
protected virtual bool ValidateOK() protected virtual bool ValidateOK()