add Avalonia Dialogs
This commit is contained in:
197
Pilz.UI.AvaloniaUI/Dialogs/AvaloniaFlyoutBase.axaml.cs
Normal file
197
Pilz.UI.AvaloniaUI/Dialogs/AvaloniaFlyoutBase.axaml.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using System.ComponentModel;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Pilz.UI.AvaloniaUI.Dialogs;
|
||||
|
||||
public partial class AvaloniaFlyoutBase : UserControl
|
||||
{
|
||||
protected readonly BackgroundWorker bgWorker_LoadData = new();
|
||||
|
||||
public delegate void OnCloseEventHandler(object? sender, EventArgs e);
|
||||
|
||||
public event OnCloseEventHandler? OnClose;
|
||||
|
||||
public static IImage? CancelImage { get; set; } = null;
|
||||
public static IImage? ConfirmImage { get; set; } = null;
|
||||
|
||||
public static readonly StyledProperty<object?> MainContentProperty = AvaloniaProperty.Register<AvaloniaFlyoutBase, object?>(nameof(MainContent));
|
||||
public static readonly StyledProperty<object?> FooterContentProperty = AvaloniaProperty.Register<AvaloniaFlyoutBase, object?>(nameof(FooterContent));
|
||||
|
||||
[Browsable(false)]
|
||||
public object? Result { get; protected set; }
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool RegisterDialogAccept { get; set; } = true;
|
||||
|
||||
[DefaultValue(true)]
|
||||
public bool RegisterDialogCancel { get; set; } = true;
|
||||
|
||||
protected AvaloniaFlyoutBase()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
CancelButtonImage = CancelImage;
|
||||
ConfirmButtonImage = ConfirmImage;
|
||||
|
||||
bgWorker_LoadData.DoWork += BgWorker_LoadData_DoWork;
|
||||
bgWorker_LoadData.RunWorkerCompleted += BgWorker_LoadData_RunWorkerCompleted;
|
||||
}
|
||||
|
||||
public object? MainContent
|
||||
{
|
||||
get => GetValue(MainContentProperty);
|
||||
set => SetValue(MainContentProperty, value);
|
||||
}
|
||||
|
||||
public object? FooterContent
|
||||
{
|
||||
get => GetValue(FooterContentProperty);
|
||||
set => SetValue(FooterContentProperty, value);
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public virtual bool ActionPanelVisible
|
||||
{
|
||||
get => StackPanelFooter.IsVisible;
|
||||
set => StackPanelFooter.IsVisible = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public virtual bool CancelButtonVisible
|
||||
{
|
||||
get => ButtonCancel.IsVisible;
|
||||
set => ButtonCancel.IsVisible = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public virtual bool ConfirmButtonVisible
|
||||
{
|
||||
get => ButtonOkay.IsVisible;
|
||||
set => ButtonOkay.IsVisible = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public virtual bool CancelButtonEnable
|
||||
{
|
||||
get => ButtonCancel.IsEnabled;
|
||||
set => ButtonCancel.IsEnabled = value;
|
||||
}
|
||||
|
||||
[DefaultValue(true)]
|
||||
public virtual bool ConfirmButtonEnable
|
||||
{
|
||||
get => ButtonOkay.IsEnabled;
|
||||
set => ButtonOkay.IsEnabled = value;
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
public virtual IImage? CancelButtonImage
|
||||
{
|
||||
get => ButtonCancel.ImageSource;
|
||||
set => ButtonCancel.ImageSource = value;
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
public virtual IImage? ConfirmButtonImage
|
||||
{
|
||||
get => ButtonOkay.ImageSource;
|
||||
set => ButtonOkay.ImageSource = value;
|
||||
}
|
||||
|
||||
[Localizable(true)]
|
||||
[DefaultValue("Okay")]
|
||||
public virtual string? ConfirmButtonText
|
||||
{
|
||||
get => ButtonOkay.Text;
|
||||
set => ButtonOkay.Text = value;
|
||||
}
|
||||
|
||||
[Localizable(true)]
|
||||
[DefaultValue("Cancel")]
|
||||
public virtual string? CancelButtonText
|
||||
{
|
||||
get => ButtonCancel.Text;
|
||||
set => ButtonCancel.Text = value;
|
||||
}
|
||||
|
||||
[Localizable(true)]
|
||||
[DefaultValue("")]
|
||||
public virtual string? Title
|
||||
{
|
||||
get => LabelTitle.Text;
|
||||
set
|
||||
{
|
||||
LabelTitle.Text = value;
|
||||
SetShowTitlePanel();
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
public virtual IImage? TitleIcon
|
||||
{
|
||||
get => ImageTitle.Source;
|
||||
set
|
||||
{
|
||||
ImageTitle.Source = value;
|
||||
SetShowTitlePanel();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void BgWorker_LoadData_DoWork(object? sender, DoWorkEventArgs e)
|
||||
{
|
||||
OnLoadData(e);
|
||||
}
|
||||
|
||||
protected virtual void BgWorker_LoadData_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
OnLoadDataCompleted(e);
|
||||
}
|
||||
|
||||
protected virtual void LoadData()
|
||||
{
|
||||
bgWorker_LoadData.RunWorkerAsync();
|
||||
}
|
||||
|
||||
protected virtual void LoadData(object? argument)
|
||||
{
|
||||
bgWorker_LoadData.RunWorkerAsync(argument);
|
||||
}
|
||||
|
||||
protected virtual void OnLoadData(DoWorkEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnLoadDataCompleted(RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
protected void Close(object? result)
|
||||
{
|
||||
Result = result;
|
||||
OnClose?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual bool ValidateOK()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void SetShowTitlePanel()
|
||||
{
|
||||
StackPanelHeader.IsVisible = !string.IsNullOrWhiteSpace(Title) || TitleIcon != null;
|
||||
}
|
||||
|
||||
protected virtual void ButtonOkay_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ValidateOK())
|
||||
Close(true);
|
||||
}
|
||||
|
||||
protected virtual void ButtonCancel_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user