diff --git a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml
index 7ab2c67..4132581 100644
--- a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml
+++ b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml
@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ursa.Demo.Dialogs"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:u="https://irihi.tech/ursa"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
d:DesignHeight="450"
@@ -30,6 +31,7 @@
HorizontalAlignment="Right"
Orientation="Horizontal"
Spacing="8">
+
diff --git a/demo/Ursa.Demo/Pages/DialogDemo.axaml b/demo/Ursa.Demo/Pages/DialogDemo.axaml
index 0ef4c5e..1e6e67f 100644
--- a/demo/Ursa.Demo/Pages/DialogDemo.axaml
+++ b/demo/Ursa.Demo/Pages/DialogDemo.axaml
@@ -36,8 +36,7 @@
OnContent="Modal" />
@@ -81,8 +80,7 @@
OnContent="Modal" />
diff --git a/demo/Ursa.Demo/Pages/DrawerDemo.axaml b/demo/Ursa.Demo/Pages/DrawerDemo.axaml
index fca5d36..c613b4e 100644
--- a/demo/Ursa.Demo/Pages/DrawerDemo.axaml
+++ b/demo/Ursa.Demo/Pages/DrawerDemo.axaml
@@ -23,13 +23,13 @@
OffContent="Local"
OnContent="Global" />
@@ -56,13 +56,13 @@
OffContent="Local"
OnContent="Global" />
diff --git a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs
index 7376432..cf5d6b3 100644
--- a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs
@@ -55,11 +55,11 @@ public class DialogDemoViewModel: ObservableObject
set => SetProperty(ref _isModal, value);
}
- private bool _canCloseMaskToClose;
- public bool CanCloseMaskToClose
+ private bool _canLightDismiss;
+ public bool CanLightDismiss
{
- get => _canCloseMaskToClose;
- set => SetProperty(ref _canCloseMaskToClose, value);
+ get => _canLightDismiss;
+ set => SetProperty(ref _canLightDismiss, value);
}
private DialogResult? _defaultResult;
@@ -118,7 +118,7 @@ public class DialogDemoViewModel: ObservableObject
Title = "Please select a date",
Mode = SelectedMode,
Buttons = SelectedButton,
- CanClickOnMaskToClose = CanCloseMaskToClose,
+ CanLightDismiss = CanLightDismiss,
HorizontalAnchor = HorizontalPosition.Right,
HorizontalOffset = 50,
VerticalAnchor = VerticalPosition.Top,
@@ -136,7 +136,8 @@ public class DialogDemoViewModel: ObservableObject
{
Title = "Please select a date",
Mode = SelectedMode,
- Buttons = SelectedButton
+ Buttons = SelectedButton,
+ CanLightDismiss = CanLightDismiss,
});
}
}
@@ -169,14 +170,15 @@ public class DialogDemoViewModel: ObservableObject
Result = await OverlayDialog.ShowCustomModal(
vm, IsGlobal ? null : "LocalHost", options: new OverlayDialogOptions()
{
- CanClickOnMaskToClose = CanCloseMaskToClose,
+ CanLightDismiss = CanLightDismiss,
});
Date = vm.Date;
}
else
{
OverlayDialog.ShowCustom(new DialogWithActionViewModel(),
- IsGlobal ? null : "LocalHost");
+ IsGlobal ? null : "LocalHost",
+ options: new OverlayDialogOptions{ CanLightDismiss = CanLightDismiss });
}
}
diff --git a/demo/Ursa.Demo/ViewModels/DrawerDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/DrawerDemoViewModel.cs
index 209eb52..e51586b 100644
--- a/demo/Ursa.Demo/ViewModels/DrawerDemoViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/DrawerDemoViewModel.cs
@@ -20,10 +20,10 @@ public partial class DrawerDemoViewModel: ObservableObject
[ObservableProperty] private Position _selectedPosition;
[ObservableProperty] private DialogButton _selectedButton;
[ObservableProperty] private bool _isGlobal;
- [ObservableProperty] private bool _canCloseMaskToClose;
+ [ObservableProperty] private bool _canLightDismiss;
[ObservableProperty] private DialogResult? _defaultResult;
[ObservableProperty] private bool _result;
- [ObservableProperty] private bool _showMask;
+ [ObservableProperty] private bool _isModal;
[ObservableProperty] private DateTime? _date;
@@ -36,32 +36,60 @@ public partial class DrawerDemoViewModel: ObservableObject
private async Task ShowDefaultDialog()
{
var vm = new PlainDialogViewModel();
- DefaultResult = await Drawer.Show(
- vm,
- IsGlobal ? null : "LocalHost",
- new DefaultDrawerOptions()
- {
- Title = "Please select a date",
- Position = SelectedPosition,
- Buttons = SelectedButton,
- CanClickOnMaskToClose = CanCloseMaskToClose,
- ShowMask = ShowMask,
- });
- Date = vm.Date;
+ if (IsModal)
+ {
+ DefaultResult = await Drawer.ShowModal(
+ vm,
+ IsGlobal ? null : "LocalHost",
+ new DrawerOptions()
+ {
+ Title = "Please select a date",
+ Position = SelectedPosition,
+ Buttons = SelectedButton,
+ CanLightDismiss = CanLightDismiss,
+ });
+ Date = vm.Date;
+ }
+ else
+ {
+ Drawer.Show(
+ vm,
+ IsGlobal ? null : "LocalHost",
+ new DrawerOptions()
+ {
+ Title = "Please select a date",
+ Position = SelectedPosition,
+ Buttons = SelectedButton,
+ CanLightDismiss = CanLightDismiss,
+ });
+ }
}
private async Task ShowCustomDrawer()
{
var vm = new DialogWithActionViewModel();
- Result = await Drawer.ShowCustom(
- vm,
- IsGlobal ? null : "LocalHost",
- new CustomDrawerOptions()
- {
- Position = SelectedPosition,
- CanClickOnMaskToClose = CanCloseMaskToClose,
- ShowMask = ShowMask,
- });
- Date = vm.Date;
+ if (IsModal)
+ {
+ Result = await Drawer.ShowCustomModal(
+ vm,
+ IsGlobal ? null : "LocalHost",
+ new DrawerOptions()
+ {
+ Position = SelectedPosition,
+ CanLightDismiss = CanLightDismiss,
+ });
+ Date = vm.Date;
+ }
+ else
+ {
+ Drawer.ShowCustom(
+ vm,
+ IsGlobal ? null : "LocalHost",
+ new DrawerOptions()
+ {
+ Position = SelectedPosition,
+ CanLightDismiss = CanLightDismiss,
+ });
+ }
}
}
\ No newline at end of file
diff --git a/demo/Ursa.Demo/Views/MainView.axaml b/demo/Ursa.Demo/Views/MainView.axaml
index 31d58a1..956dbe4 100644
--- a/demo/Ursa.Demo/Views/MainView.axaml
+++ b/demo/Ursa.Demo/Views/MainView.axaml
@@ -16,81 +16,89 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/Ursa.PrismDialogDemo/MainWindow.axaml b/demo/Ursa.PrismDialogDemo/MainWindow.axaml
index 6acc99a..98ebde8 100644
--- a/demo/Ursa.PrismDialogDemo/MainWindow.axaml
+++ b/demo/Ursa.PrismDialogDemo/MainWindow.axaml
@@ -8,7 +8,8 @@
Title="Ursa.PrismDialogDemo">
-
+
+
diff --git a/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs b/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs
index ad95fd4..1b51033 100644
--- a/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs
+++ b/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs
@@ -7,15 +7,22 @@ namespace Ursa.PrismDialogDemo;
public partial class MainWindow : Window
{
- private IUrsaOverlayDialogService _ursa;
- public MainWindow(IUrsaOverlayDialogService ursa)
+ private IUrsaOverlayDialogService _dialogService;
+ private IUrsaDrawerService _drawerService;
+ public MainWindow(IUrsaOverlayDialogService dialogService, IUrsaDrawerService drawerService)
{
InitializeComponent();
- _ursa = ursa;
+ _dialogService = dialogService;
+ _drawerService = drawerService;
}
- private void Button_OnClick(object? sender, RoutedEventArgs e)
+ private void DialogButton_OnClick(object? sender, RoutedEventArgs e)
{
- _ursa.ShowModal("Default", null, null, null);
+ _dialogService.ShowModal("Default", null, null, null);
+ }
+
+ private void DrawerButton_OnClick(object? sender, RoutedEventArgs e)
+ {
+ _drawerService.ShowModal("Default", null, null, null);
}
}
\ No newline at end of file
diff --git a/src/Ursa.PrismExtension/IUrsaDrawerService.cs b/src/Ursa.PrismExtension/IUrsaDrawerService.cs
index 7d97bfc..77f7dc9 100644
--- a/src/Ursa.PrismExtension/IUrsaDrawerService.cs
+++ b/src/Ursa.PrismExtension/IUrsaDrawerService.cs
@@ -5,6 +5,8 @@ namespace Ursa.PrismExtension;
public interface IUrsaDrawerService
{
- public Task ShowDrawer(string viewName, object? vm, string? hostId = null, DefaultDrawerOptions? options = null);
- public Task ShowCustomDrawer(string viewName, object? vm, string? hostId = null, CustomDrawerOptions? options = null);
+ public void Show(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
+ public void ShowCustom(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
+ public Task ShowModal(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
+ public Task ShowCustomModal(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
}
\ No newline at end of file
diff --git a/src/Ursa.PrismExtension/UrsaDrawerService.cs b/src/Ursa.PrismExtension/UrsaDrawerService.cs
index 99b9a43..7cd7add 100644
--- a/src/Ursa.PrismExtension/UrsaDrawerService.cs
+++ b/src/Ursa.PrismExtension/UrsaDrawerService.cs
@@ -7,16 +7,27 @@ namespace Ursa.PrismExtension;
public class UrsaDrawerService(IContainerExtension container): IUrsaDrawerService
{
- public Task ShowDrawer(string viewName, object? vm, string? hostId = null, DefaultDrawerOptions? options = null)
+ public void Show(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
{
var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
- return Drawer.Show(v, vm, hostId, options);
+ Drawer.Show(v, vm, hostId, options);
}
-
- public Task ShowCustomDrawer(string viewName, object? vm, string? hostId = null,
- CustomDrawerOptions? options = null)
+
+ public void ShowCustom(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
{
var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
- return Drawer.ShowCustom(v, vm, hostId, options);
+ Drawer.ShowCustom(v, vm, hostId, options);
+ }
+
+ public Task ShowModal(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
+ {
+ var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
+ return Drawer.ShowModal(v, vm, hostId, options);
+ }
+
+ public Task ShowCustomModal(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
+ {
+ var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
+ return Drawer.ShowCustomModal(v, vm, hostId, options);
}
}
\ No newline at end of file
diff --git a/src/Ursa/Controls/Dialog/DialogControlBase.cs b/src/Ursa/Controls/Dialog/DialogControlBase.cs
index abfdd70..5c45fb4 100644
--- a/src/Ursa/Controls/Dialog/DialogControlBase.cs
+++ b/src/Ursa/Controls/Dialog/DialogControlBase.cs
@@ -1,8 +1,10 @@
+using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
+using Avalonia.LogicalTree;
using Irihi.Avalonia.Shared.Helpers;
using Ursa.Common;
using Ursa.Controls.OverlayShared;
@@ -13,12 +15,12 @@ namespace Ursa.Controls;
[TemplatePart(PART_CloseButton, typeof(Button))]
[TemplatePart(PART_TitleArea, typeof(Panel))]
[PseudoClasses(PC_Modal)]
-public abstract class DialogControlBase: OverlayFeedbackElement
+public abstract class DialogControlBase : OverlayFeedbackElement
{
public const string PART_CloseButton = "PART_CloseButton";
public const string PART_TitleArea = "PART_TitleArea";
public const string PC_Modal = ":modal";
-
+
internal HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
internal VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
internal HorizontalPosition ActualHorizontalAnchor { get; set; }
@@ -27,19 +29,18 @@ public abstract class DialogControlBase: OverlayFeedbackElement
internal double? VerticalOffset { get; set; }
internal double? HorizontalOffsetRatio { get; set; }
internal double? VerticalOffsetRatio { get; set; }
- internal bool CanClickOnMaskToClose { get; set; }
internal bool CanLightDismiss { get; set; }
-
+ internal bool CanDragMove { get; set; }
+
protected internal Button? _closeButton;
private Panel? _titleArea;
-
- internal void SetAsModal(bool modal)
- {
- PseudoClasses.Set(PC_Modal, modal);
- }
-
- public static readonly RoutedEvent LayerChangedEvent = RoutedEvent.Register(
- nameof(LayerChanged), RoutingStrategies.Bubble);
+
+ #region Layer Management
+
+ public static readonly RoutedEvent LayerChangedEvent =
+ RoutedEvent.Register(
+ nameof(LayerChanged), RoutingStrategies.Bubble);
+
public event EventHandler LayerChanged
{
add => AddHandler(LayerChangedEvent, value);
@@ -54,35 +55,133 @@ public abstract class DialogControlBase: OverlayFeedbackElement
}
}
+ #endregion
+
+ #region DragMove AttachedPropert
+
+ public static readonly AttachedProperty CanDragMoveProperty =
+ AvaloniaProperty.RegisterAttached("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 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() is { } dialog)
+ {
+ e.Source = dialog;
+ }
+ }
+
+ void OnPointerMoved(InputElement sender, PointerEventArgs e)
+ {
+ if (sender.FindLogicalAncestorOfType() is { } dialog)
+ {
+ e.Source = dialog;
+ }
+ }
+
+ void OnPointerReleased(InputElement sender, PointerReleasedEventArgs e)
+ {
+ if (sender.FindLogicalAncestorOfType() is { } dialog)
+ {
+ e.Source = dialog;
+ }
+ }
+ }
+
+ #endregion
+
+ #region Close AttachedProperty
+
+ public static readonly AttachedProperty CanCloseProperty =
+ AvaloniaProperty.RegisterAttached("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 arg2)
+ {
+ if (arg2.NewValue.Value)
+ {
+ arg1.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Bubble);
+ }
+ void OnPointerPressed(InputElement sender, PointerPressedEventArgs e)
+ {
+ if (sender.FindLogicalAncestorOfType() is { } dialog)
+ {
+ dialog.Close();
+ }
+ }
+ }
+ #endregion
+
+ static DialogControlBase()
+ {
+ CanDragMoveProperty.Changed.AddClassHandler(OnCanDragMoveChanged);
+ CanCloseProperty.Changed.AddClassHandler(OnCanCloseChanged);
+ }
+
+
+
+
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
- _titleArea?.RemoveHandler(PointerMovedEvent, OnTitlePointerMove);
- _titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed);
- _titleArea?.RemoveHandler(PointerReleasedEvent, OnTitlePointerRelease);
_titleArea = e.NameScope.Find(PART_TitleArea);
- _titleArea?.AddHandler(PointerMovedEvent, OnTitlePointerMove, RoutingStrategies.Bubble);
- _titleArea?.AddHandler(PointerPressedEvent, OnTitlePointerPressed, RoutingStrategies.Bubble);
- _titleArea?.AddHandler(PointerReleasedEvent, OnTitlePointerRelease, RoutingStrategies.Bubble);
+ if (CanDragMove)
+ {
+ _titleArea?.RemoveHandler(PointerMovedEvent, OnTitlePointerMove);
+ _titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed);
+ _titleArea?.RemoveHandler(PointerReleasedEvent, OnTitlePointerRelease);
+
+ _titleArea?.AddHandler(PointerMovedEvent, OnTitlePointerMove, RoutingStrategies.Bubble);
+ _titleArea?.AddHandler(PointerPressedEvent, OnTitlePointerPressed, RoutingStrategies.Bubble);
+ _titleArea?.AddHandler(PointerReleasedEvent, OnTitlePointerRelease, RoutingStrategies.Bubble);
+ }
+ else
+ {
+ if (_titleArea is not null) _titleArea.IsHitTestVisible = false;
+ }
+
Button.ClickEvent.RemoveHandler(OnCloseButtonClick, _closeButton);
_closeButton = e.NameScope.Find