feat: respect close button visibility in all options.
This commit is contained in:
@@ -20,6 +20,22 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
public const string PC_Modal = ":modal";
|
||||
public const string PC_FullScreen = ":full-screen";
|
||||
|
||||
public static readonly DirectProperty<DialogControlBase, bool> IsFullScreenProperty =
|
||||
AvaloniaProperty.RegisterDirect<DialogControlBase, bool>(
|
||||
nameof(IsFullScreen), o => o.IsFullScreen, (o, v) => o.IsFullScreen = v);
|
||||
|
||||
protected internal Button? _closeButton;
|
||||
|
||||
private bool _isFullScreen;
|
||||
private Panel? _titleArea;
|
||||
|
||||
static DialogControlBase()
|
||||
{
|
||||
CanDragMoveProperty.Changed.AddClassHandler<InputElement, bool>(OnCanDragMoveChanged);
|
||||
CanCloseProperty.Changed.AddClassHandler<InputElement, bool>(OnCanCloseChanged);
|
||||
IsFullScreenProperty.AffectsPseudoClass<DialogControlBase>(PC_FullScreen);
|
||||
}
|
||||
|
||||
internal HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
|
||||
internal VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
|
||||
internal HorizontalPosition ActualHorizontalAnchor { get; set; }
|
||||
@@ -29,11 +45,7 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
internal double? HorizontalOffsetRatio { get; set; }
|
||||
internal double? VerticalOffsetRatio { get; set; }
|
||||
internal bool CanLightDismiss { get; set; }
|
||||
|
||||
private bool _isFullScreen;
|
||||
|
||||
public static readonly DirectProperty<DialogControlBase, bool> IsFullScreenProperty = AvaloniaProperty.RegisterDirect<DialogControlBase, bool>(
|
||||
nameof(IsFullScreen), o => o.IsFullScreen, (o, v) => o.IsFullScreen = v);
|
||||
internal bool? IsCloseButtonVisible { get; set; }
|
||||
|
||||
public bool IsFullScreen
|
||||
{
|
||||
@@ -41,113 +53,6 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
set => SetAndRaise(IsFullScreenProperty, ref _isFullScreen, value);
|
||||
}
|
||||
|
||||
protected internal Button? _closeButton;
|
||||
private Panel? _titleArea;
|
||||
|
||||
#region Layer Management
|
||||
|
||||
public static readonly RoutedEvent<DialogLayerChangeEventArgs> LayerChangedEvent =
|
||||
RoutedEvent.Register<CustomDialogControl, DialogLayerChangeEventArgs>(
|
||||
nameof(LayerChanged), RoutingStrategies.Bubble);
|
||||
|
||||
public event EventHandler<DialogLayerChangeEventArgs> LayerChanged
|
||||
{
|
||||
add => AddHandler(LayerChangedEvent, value);
|
||||
remove => RemoveHandler(LayerChangedEvent, value);
|
||||
}
|
||||
|
||||
public void UpdateLayer(object? o)
|
||||
{
|
||||
if (o is DialogLayerChangeType t)
|
||||
{
|
||||
RaiseEvent(new DialogLayerChangeEventArgs(LayerChangedEvent, t));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DragMove AttachedPropert
|
||||
|
||||
public static readonly AttachedProperty<bool> CanDragMoveProperty =
|
||||
AvaloniaProperty.RegisterAttached<DialogControlBase, InputElement, bool>("CanDragMove");
|
||||
|
||||
public static void SetCanDragMove(InputElement obj, bool value) => obj.SetValue(CanDragMoveProperty, value);
|
||||
public static bool GetCanDragMove(InputElement obj) => obj.GetValue(CanDragMoveProperty);
|
||||
|
||||
private static void OnCanDragMoveChanged(InputElement arg1, AvaloniaPropertyChangedEventArgs<bool> arg2)
|
||||
{
|
||||
if (arg2.NewValue.Value)
|
||||
{
|
||||
arg1.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Bubble);
|
||||
arg1.AddHandler(PointerMovedEvent, OnPointerMoved, RoutingStrategies.Bubble);
|
||||
arg1.AddHandler(PointerReleasedEvent, OnPointerReleased, RoutingStrategies.Bubble);
|
||||
}
|
||||
else
|
||||
{
|
||||
arg1.RemoveHandler(PointerPressedEvent, OnPointerPressed);
|
||||
arg1.RemoveHandler(PointerMovedEvent, OnPointerMoved);
|
||||
arg1.RemoveHandler(PointerReleasedEvent, OnPointerReleased);
|
||||
}
|
||||
|
||||
void OnPointerPressed(InputElement sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog)
|
||||
{
|
||||
e.Source = dialog;
|
||||
}
|
||||
}
|
||||
|
||||
void OnPointerMoved(InputElement sender, PointerEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog)
|
||||
{
|
||||
e.Source = dialog;
|
||||
}
|
||||
}
|
||||
|
||||
void OnPointerReleased(InputElement sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog)
|
||||
{
|
||||
e.Source = dialog;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Close AttachedProperty
|
||||
|
||||
public static readonly AttachedProperty<bool> CanCloseProperty =
|
||||
AvaloniaProperty.RegisterAttached<DialogControlBase, InputElement, bool>("CanClose");
|
||||
|
||||
public static void SetCanClose(InputElement obj, bool value) => obj.SetValue(CanCloseProperty, value);
|
||||
public static bool GetCanClose(InputElement obj) => obj.GetValue(CanCloseProperty);
|
||||
private static void OnCanCloseChanged(InputElement arg1, AvaloniaPropertyChangedEventArgs<bool> arg2)
|
||||
{
|
||||
if (arg2.NewValue.Value)
|
||||
{
|
||||
arg1.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Bubble);
|
||||
}
|
||||
void OnPointerPressed(InputElement sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog)
|
||||
{
|
||||
dialog.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
static DialogControlBase()
|
||||
{
|
||||
CanDragMoveProperty.Changed.AddClassHandler<InputElement, bool>(OnCanDragMoveChanged);
|
||||
CanCloseProperty.Changed.AddClassHandler<InputElement, bool>(OnCanCloseChanged);
|
||||
IsFullScreenProperty.AffectsPseudoClass<DialogControlBase>(PC_FullScreen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
@@ -188,10 +93,107 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
e.Source = this;
|
||||
}
|
||||
|
||||
private void OnCloseButtonClick(object? sender, RoutedEventArgs args) => Close();
|
||||
private void OnCloseButtonClick(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
internal void SetAsModal(bool modal)
|
||||
{
|
||||
PseudoClasses.Set(PC_Modal, modal);
|
||||
}
|
||||
|
||||
#region Layer Management
|
||||
|
||||
public static readonly RoutedEvent<DialogLayerChangeEventArgs> LayerChangedEvent =
|
||||
RoutedEvent.Register<CustomDialogControl, DialogLayerChangeEventArgs>(
|
||||
nameof(LayerChanged), RoutingStrategies.Bubble);
|
||||
|
||||
public event EventHandler<DialogLayerChangeEventArgs> LayerChanged
|
||||
{
|
||||
add => AddHandler(LayerChangedEvent, value);
|
||||
remove => RemoveHandler(LayerChangedEvent, value);
|
||||
}
|
||||
|
||||
public void UpdateLayer(object? o)
|
||||
{
|
||||
if (o is DialogLayerChangeType t) RaiseEvent(new DialogLayerChangeEventArgs(LayerChangedEvent, t));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DragMove AttachedPropert
|
||||
|
||||
public static readonly AttachedProperty<bool> CanDragMoveProperty =
|
||||
AvaloniaProperty.RegisterAttached<DialogControlBase, InputElement, bool>("CanDragMove");
|
||||
|
||||
public static void SetCanDragMove(InputElement obj, bool value)
|
||||
{
|
||||
obj.SetValue(CanDragMoveProperty, value);
|
||||
}
|
||||
|
||||
public static bool GetCanDragMove(InputElement obj)
|
||||
{
|
||||
return obj.GetValue(CanDragMoveProperty);
|
||||
}
|
||||
|
||||
private static void OnCanDragMoveChanged(InputElement arg1, AvaloniaPropertyChangedEventArgs<bool> arg2)
|
||||
{
|
||||
if (arg2.NewValue.Value)
|
||||
{
|
||||
arg1.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Bubble);
|
||||
arg1.AddHandler(PointerMovedEvent, OnPointerMoved, RoutingStrategies.Bubble);
|
||||
arg1.AddHandler(PointerReleasedEvent, OnPointerReleased, RoutingStrategies.Bubble);
|
||||
}
|
||||
else
|
||||
{
|
||||
arg1.RemoveHandler(PointerPressedEvent, OnPointerPressed);
|
||||
arg1.RemoveHandler(PointerMovedEvent, OnPointerMoved);
|
||||
arg1.RemoveHandler(PointerReleasedEvent, OnPointerReleased);
|
||||
}
|
||||
|
||||
void OnPointerPressed(InputElement sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog) e.Source = dialog;
|
||||
}
|
||||
|
||||
void OnPointerMoved(InputElement sender, PointerEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog) e.Source = dialog;
|
||||
}
|
||||
|
||||
void OnPointerReleased(InputElement sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog) e.Source = dialog;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Close AttachedProperty
|
||||
|
||||
public static readonly AttachedProperty<bool> CanCloseProperty =
|
||||
AvaloniaProperty.RegisterAttached<DialogControlBase, InputElement, bool>("CanClose");
|
||||
|
||||
public static void SetCanClose(InputElement obj, bool value)
|
||||
{
|
||||
obj.SetValue(CanCloseProperty, value);
|
||||
}
|
||||
|
||||
public static bool GetCanClose(InputElement obj)
|
||||
{
|
||||
return obj.GetValue(CanCloseProperty);
|
||||
}
|
||||
|
||||
private static void OnCanCloseChanged(InputElement arg1, AvaloniaPropertyChangedEventArgs<bool> arg2)
|
||||
{
|
||||
if (arg2.NewValue.Value) arg1.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Bubble);
|
||||
|
||||
void OnPointerPressed(InputElement sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender.FindLogicalAncestorOfType<DialogControlBase>() is { } dialog) dialog.Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user