feat: setup demo.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
@@ -15,6 +18,20 @@ public static class DialogBox
|
||||
{
|
||||
TView t = new TView();
|
||||
t.DataContext = vm;
|
||||
return;
|
||||
}
|
||||
|
||||
public static async Task<object?> ShowOverlayAsync<TView, TViewModel>(TViewModel vm, string hostId)
|
||||
where TView : Control, new()
|
||||
where TViewModel: new()
|
||||
{
|
||||
var t = new Border()
|
||||
{
|
||||
Width = 100, Height = 100, Background = Brushes.Aqua, BorderBrush = Brushes.Yellow,
|
||||
BorderThickness = new Thickness(1)
|
||||
};
|
||||
t.DataContext = vm;
|
||||
var host = OverlayDialogManager.GetOverlayDialogHost(hostId);
|
||||
host?.Children.Add(t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,40 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Utilities;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class DialogHost: Canvas
|
||||
public class OverlayDialogHost: Canvas
|
||||
{
|
||||
public static readonly StyledProperty<string> HostIdProperty = AvaloniaProperty.Register<OverlayDialogHost, string>(
|
||||
nameof(HostId));
|
||||
|
||||
public string HostId
|
||||
{
|
||||
get => GetValue(HostIdProperty);
|
||||
set => SetValue(HostIdProperty, value);
|
||||
}
|
||||
|
||||
private Point _lastPoint;
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
OverlayDialogManager.RegisterOverlayDialogHost(this, HostId);
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
OverlayDialogManager.UnregisterOverlayDialogHost(HostId);
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
}
|
||||
|
||||
protected override void OnPointerMoved(PointerEventArgs e)
|
||||
{
|
||||
base.OnPointerMoved(e);
|
||||
if (e.Source is DialogControl item)
|
||||
if (e.Source is Control item)
|
||||
{
|
||||
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
||||
{
|
||||
@@ -31,7 +53,7 @@ public class DialogHost: Canvas
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
base.OnPointerPressed(e);
|
||||
if (e.Source is DialogControl item)
|
||||
if (e.Source is Control item)
|
||||
{
|
||||
_lastPoint = e.GetPosition(item);
|
||||
}
|
||||
23
src/Ursa/Controls/Dialog/OverlayDialogManager.cs
Normal file
23
src/Ursa/Controls/Dialog/OverlayDialogManager.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
internal static class OverlayDialogManager
|
||||
{
|
||||
private static ConcurrentDictionary<string, OverlayDialogHost> _hosts = new();
|
||||
|
||||
public static void RegisterOverlayDialogHost(OverlayDialogHost host, string id)
|
||||
{
|
||||
_hosts.TryAdd(id, host);
|
||||
}
|
||||
|
||||
public static void UnregisterOverlayDialogHost(string id)
|
||||
{
|
||||
_hosts.TryRemove(id, out _);
|
||||
}
|
||||
|
||||
public static OverlayDialogHost? GetOverlayDialogHost(string id)
|
||||
{
|
||||
return _hosts.TryGetValue(id, out var host) ? host : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user