113 lines
3.6 KiB
C#
113 lines
3.6 KiB
C#
using Telerik.WinControls;
|
|
using Telerik.WinControls.Svg;
|
|
using Telerik.WinControls.UI;
|
|
using Telerik.WinControls.UI.SplashScreen;
|
|
|
|
namespace Pilz.UI.Telerik.Dialogs;
|
|
|
|
partial class RadFlyoutBase
|
|
{
|
|
public delegate void FlyoutCreatedEventHandler(FlyoutCreatedEventArgs e);
|
|
public delegate void FlyoutClosedEventHandler(FlyoutClosedEventArgs e);
|
|
|
|
public static event FlyoutCreatedEventHandler FlyoutCreated
|
|
{
|
|
add => flyoutCreatedHandlers.Add(value);
|
|
remove => flyoutCreatedHandlers.Remove(value);
|
|
}
|
|
|
|
public static event FlyoutClosedEventHandler FlyoutClosed
|
|
{
|
|
add => flyoutCloseHandlers.Add(value);
|
|
remove => flyoutCloseHandlers.Remove(value);
|
|
}
|
|
|
|
private static readonly List<FlyoutCreatedEventHandler> flyoutCreatedHandlers = new();
|
|
private static readonly List<FlyoutClosedEventHandler> flyoutCloseHandlers = new();
|
|
|
|
private static object? tagToAssign = null;
|
|
private static string? titleToAssing = null;
|
|
private static RadSvgImage? iconToAssign = null;
|
|
|
|
public static Control? ParentContext { get; private set; } = null;
|
|
|
|
static RadFlyoutBase()
|
|
{
|
|
RadFlyoutManager.ContentCreated += RadFlyoutManager_ContentCreated;
|
|
RadFlyoutManager.FlyoutClosed += RadFlyoutManager_FlyoutClosed;
|
|
}
|
|
|
|
private static void RadFlyoutManager_ContentCreated(ContentCreatedEventArgs e)
|
|
{
|
|
if (e.Content is RadFlyoutBase dialogBase)
|
|
{
|
|
if (tagToAssign != null)
|
|
dialogBase.Tag = tagToAssign;
|
|
|
|
if (titleToAssing != null)
|
|
dialogBase.Title = titleToAssing;
|
|
|
|
if (iconToAssign != null)
|
|
dialogBase.TitleIcon = iconToAssign;
|
|
|
|
var eventArgs = new FlyoutCreatedEventArgs(dialogBase);
|
|
|
|
if (dialogBase is ILoadContent iLoadContent)
|
|
iLoadContent.LoadContent();
|
|
|
|
foreach (var args in flyoutCreatedHandlers)
|
|
{
|
|
if (ParentContext != null)
|
|
ParentContext?.Invoke(args, eventArgs);
|
|
else
|
|
args.Invoke(eventArgs);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void RadFlyoutManager_FlyoutClosed(global::Telerik.WinControls.UI.SplashScreen.FlyoutClosedEventArgs e)
|
|
{
|
|
if (e.Content is RadFlyoutBase dialogBase)
|
|
{
|
|
var eventArgs = new FlyoutClosedEventArgs((RadFlyoutBase)e.Content);
|
|
|
|
foreach (var args in flyoutCloseHandlers)
|
|
{
|
|
if (ParentContext != null)
|
|
ParentContext?.Invoke(args, eventArgs);
|
|
else
|
|
args.Invoke(eventArgs);
|
|
}
|
|
}
|
|
|
|
ParentContext = null;
|
|
}
|
|
|
|
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;
|
|
RadFlyoutManager.Show(controlToAssociate, flyoutContentType);
|
|
}
|
|
|
|
protected static void CloseFlyout()
|
|
{
|
|
if (ParentContext == null)
|
|
throw new NullReferenceException(nameof(ParentContext));
|
|
|
|
ParentContext.BeginInvoke(RadFlyoutManager.Close);
|
|
}
|
|
}
|