feat: setup demo.
This commit is contained in:
@@ -6,6 +6,7 @@ public static class MenuKeys
|
|||||||
public const string MenuKeyBadge = "Badge";
|
public const string MenuKeyBadge = "Badge";
|
||||||
public const string MenuKeyBanner = "Banner";
|
public const string MenuKeyBanner = "Banner";
|
||||||
public const string MenuKeyButtonGroup = "ButtonGroup";
|
public const string MenuKeyButtonGroup = "ButtonGroup";
|
||||||
|
public const string MenuKeyDialog = "Dialog";
|
||||||
public const string MenuKeyDivider = "Divider";
|
public const string MenuKeyDivider = "Divider";
|
||||||
public const string MenuKeyDualBadge = "DualBadge";
|
public const string MenuKeyDualBadge = "DualBadge";
|
||||||
public const string MenuKeyImageViewer = "ImageViewer";
|
public const string MenuKeyImageViewer = "ImageViewer";
|
||||||
|
|||||||
29
demo/Ursa.Demo/Pages/DialogDemo.axaml
Normal file
29
demo/Ursa.Demo/Pages/DialogDemo.axaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<UserControl
|
||||||
|
x:Class="Ursa.Demo.Pages.DialogDemo"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
|
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||||
|
d:DesignHeight="450"
|
||||||
|
d:DesignWidth="800"
|
||||||
|
x:CompileBindings="True"
|
||||||
|
x:DataType="vm:DialogDemoViewModel"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<Grid ColumnDefinitions="Auto, *">
|
||||||
|
<StackPanel Grid.Column="0">
|
||||||
|
<Button Command="{Binding ShowLocalOverlayDialogCommand}">Show Local Overlay Dialog</Button>
|
||||||
|
<Button Command="{Binding ShowGlobalOverlayDialogCommand}"> Show Global Overlay Dialog </Button>
|
||||||
|
</StackPanel>
|
||||||
|
<Grid Grid.Column="1">
|
||||||
|
<Button
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Command="{Binding ShowLocalOverlayDialogCommand}">
|
||||||
|
Show Local Overlay Dialog
|
||||||
|
</Button>
|
||||||
|
<u:OverlayDialogHost HostId="LocalHost" />
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
13
demo/Ursa.Demo/Pages/DialogDemo.axaml.cs
Normal file
13
demo/Ursa.Demo/Pages/DialogDemo.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.Pages;
|
||||||
|
|
||||||
|
public partial class DialogDemo : UserControl
|
||||||
|
{
|
||||||
|
public DialogDemo()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
31
demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs
Normal file
31
demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Shapes;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Ursa.Controls;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
|
public class DialogDemoViewModel: ObservableObject
|
||||||
|
{
|
||||||
|
public ICommand ShowLocalOverlayDialogCommand { get; }
|
||||||
|
public ICommand ShowGlobalOverlayDialogCommand { get; }
|
||||||
|
|
||||||
|
public DialogDemoViewModel()
|
||||||
|
{
|
||||||
|
ShowLocalOverlayDialogCommand = new RelayCommand(ShowLocalOverlayDialog);
|
||||||
|
ShowGlobalOverlayDialogCommand = new RelayCommand(ShowGlobalOverlayDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ShowGlobalOverlayDialog()
|
||||||
|
{
|
||||||
|
await DialogBox.ShowOverlayAsync<Banner, DateTime>(DateTime.Now, "GlobalHost");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ShowLocalOverlayDialog()
|
||||||
|
{
|
||||||
|
await DialogBox.ShowOverlayAsync<Banner, DateTime>(DateTime.Now, "LocalHost");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ public class MainViewViewModel : ViewModelBase
|
|||||||
MenuKeys.MenuKeyBadge => new BadgeDemoViewModel(),
|
MenuKeys.MenuKeyBadge => new BadgeDemoViewModel(),
|
||||||
MenuKeys.MenuKeyBanner => new BannerDemoViewModel(),
|
MenuKeys.MenuKeyBanner => new BannerDemoViewModel(),
|
||||||
MenuKeys.MenuKeyButtonGroup => new ButtonGroupDemoViewModel(),
|
MenuKeys.MenuKeyButtonGroup => new ButtonGroupDemoViewModel(),
|
||||||
|
MenuKeys.MenuKeyDialog => new DialogDemoViewModel(),
|
||||||
MenuKeys.MenuKeyDivider => new DividerDemoViewModel(),
|
MenuKeys.MenuKeyDivider => new DividerDemoViewModel(),
|
||||||
MenuKeys.MenuKeyDualBadge => new DualBadgeDemoViewModel(),
|
MenuKeys.MenuKeyDualBadge => new DualBadgeDemoViewModel(),
|
||||||
MenuKeys.MenuKeyImageViewer => new ImageViewerDemoViewModel(),
|
MenuKeys.MenuKeyImageViewer => new ImageViewerDemoViewModel(),
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class MenuViewModel: ViewModelBase
|
|||||||
new() { MenuHeader = "Badge", Key = MenuKeys.MenuKeyBadge },
|
new() { MenuHeader = "Badge", Key = MenuKeys.MenuKeyBadge },
|
||||||
new() { MenuHeader = "Banner", Key = MenuKeys.MenuKeyBanner },
|
new() { MenuHeader = "Banner", Key = MenuKeys.MenuKeyBanner },
|
||||||
new() { MenuHeader = "ButtonGroup", Key = MenuKeys.MenuKeyButtonGroup },
|
new() { MenuHeader = "ButtonGroup", Key = MenuKeys.MenuKeyButtonGroup },
|
||||||
|
new() { MenuHeader = "Dialog", Key = MenuKeys.MenuKeyDialog },
|
||||||
new() { MenuHeader = "Divider", Key = MenuKeys.MenuKeyDivider },
|
new() { MenuHeader = "Divider", Key = MenuKeys.MenuKeyDivider },
|
||||||
new() { MenuHeader = "DualBadge", Key = MenuKeys.MenuKeyDualBadge },
|
new() { MenuHeader = "DualBadge", Key = MenuKeys.MenuKeyDualBadge },
|
||||||
new() { MenuHeader = "IconButton", Key = MenuKeys.MenuKeyIconButton },
|
new() { MenuHeader = "IconButton", Key = MenuKeys.MenuKeyIconButton },
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
<converters:ViewLocator />
|
<converters:ViewLocator />
|
||||||
</ContentControl.ContentTemplate>
|
</ContentControl.ContentTemplate>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
|
<u:OverlayDialogHost Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" HostId="GlobalHost" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Shapes;
|
||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
@@ -15,6 +18,20 @@ public static class DialogBox
|
|||||||
{
|
{
|
||||||
TView t = new TView();
|
TView t = new TView();
|
||||||
t.DataContext = vm;
|
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;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Media;
|
||||||
using Avalonia.Utilities;
|
using Avalonia.Utilities;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
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;
|
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)
|
protected override void OnPointerMoved(PointerEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPointerMoved(e);
|
base.OnPointerMoved(e);
|
||||||
if (e.Source is DialogControl item)
|
if (e.Source is Control item)
|
||||||
{
|
{
|
||||||
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
||||||
{
|
{
|
||||||
@@ -31,7 +53,7 @@ public class DialogHost: Canvas
|
|||||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPointerPressed(e);
|
base.OnPointerPressed(e);
|
||||||
if (e.Source is DialogControl item)
|
if (e.Source is Control item)
|
||||||
{
|
{
|
||||||
_lastPoint = e.GetPosition(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