DragAndDrop core
This commit is contained in:
83
Lattice.Layout.UI.WinUI/Docking/DockOverlay.cs
Normal file
83
Lattice.Layout.UI.WinUI/Docking/DockOverlay.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Lattice.Layout.Abstractions;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Lattice.Layout.UI.WinUI.Docking;
|
||||
|
||||
/// <summary>
|
||||
/// Полупрозрачная подсветка зоны докинга.
|
||||
/// </summary>
|
||||
public sealed class DockOverlay : Control
|
||||
{
|
||||
public static readonly DependencyProperty ZoneProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(Zone),
|
||||
typeof(DockZone),
|
||||
typeof(DockOverlay),
|
||||
new PropertyMetadata(DockZone.Center, OnVisualPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty BoundsProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(Bounds),
|
||||
typeof(Rect),
|
||||
typeof(DockOverlay),
|
||||
new PropertyMetadata(Rect.Empty, OnVisualPropertyChanged));
|
||||
|
||||
/// <summary>
|
||||
/// Зона докинга, которую нужно подсветить.
|
||||
/// </summary>
|
||||
public DockZone Zone
|
||||
{
|
||||
get => (DockZone)GetValue(ZoneProperty);
|
||||
set => SetValue(ZoneProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прямоугольник зоны в координатах родительского контейнера.
|
||||
/// </summary>
|
||||
public Rect Bounds
|
||||
{
|
||||
get => (Rect)GetValue(BoundsProperty);
|
||||
set => SetValue(BoundsProperty, value);
|
||||
}
|
||||
|
||||
private Border? _border;
|
||||
|
||||
public DockOverlay()
|
||||
{
|
||||
IsHitTestVisible = false;
|
||||
DefaultStyleKey = typeof(DockOverlay);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
_border = GetTemplateChild("PART_Border") as Border;
|
||||
UpdateVisual();
|
||||
}
|
||||
|
||||
private static void OnVisualPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is DockOverlay overlay)
|
||||
{
|
||||
overlay.UpdateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVisual()
|
||||
{
|
||||
if (_border is null)
|
||||
return;
|
||||
|
||||
Canvas.SetLeft(this, Bounds.X);
|
||||
Canvas.SetTop(this, Bounds.Y);
|
||||
Width = Bounds.Width;
|
||||
Height = Bounds.Height;
|
||||
|
||||
_border.BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.DeepSkyBlue);
|
||||
_border.BorderThickness = new Thickness(2);
|
||||
_border.Background = new SolidColorBrush(Microsoft.UI.Colors.LightSkyBlue) { Opacity = 0.25 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user