diff --git a/DeedyDesigner/Deedy.Testing/MainWindow.xaml b/DeedyDesigner/Deedy.Testing/MainWindow.xaml
index 1865e98..5940972 100644
--- a/DeedyDesigner/Deedy.Testing/MainWindow.xaml
+++ b/DeedyDesigner/Deedy.Testing/MainWindow.xaml
@@ -14,8 +14,8 @@
-
-
-
+
+
+
diff --git a/DeedyDesigner/Deedy.Testing/MainWindow.xaml.cs b/DeedyDesigner/Deedy.Testing/MainWindow.xaml.cs
index 681e031..dc47a99 100644
--- a/DeedyDesigner/Deedy.Testing/MainWindow.xaml.cs
+++ b/DeedyDesigner/Deedy.Testing/MainWindow.xaml.cs
@@ -25,5 +25,10 @@ namespace Deedy
{
}
+
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ DrawerManager.ShowDrawer(this.decorator, new Border() { Background = Brushes.Red, MinWidth = 400, MinHeight = 400, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch });
+ }
}
}
\ No newline at end of file
diff --git a/DeedyDesigner/Deedy.Testing/SlideDrawerAdorner.cs b/DeedyDesigner/Deedy.Testing/SlideDrawerAdorner.cs
new file mode 100644
index 0000000..a52e008
--- /dev/null
+++ b/DeedyDesigner/Deedy.Testing/SlideDrawerAdorner.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+
+namespace Deedy
+{
+ ///
+ /// 简化的蒙层装饰器
+ ///
+ public class SlideDrawerAdorner : Adorner
+ {
+ private readonly VisualCollection _visuals;
+ private readonly FrameworkElement _content;
+ private readonly Border _mask;
+
+ public SlideDrawerAdorner(UIElement adornedElement, FrameworkElement content, double maskOpacity = 0.5)
+ : base(adornedElement)
+ {
+ _visuals = new VisualCollection(this);
+
+ // 创建蒙层
+ _mask = new Border
+ {
+ Background = Brushes.Black,
+ Opacity = maskOpacity
+ };
+ _mask.MouseLeftButtonDown += (s, e) => CloseRequested?.Invoke(this, EventArgs.Empty);
+
+ // 添加内容
+ _content = content;
+
+ _visuals.Add(_mask);
+ //_visuals.Add(_content);
+ _mask.Child = _content;
+ }
+
+ public event EventHandler? CloseRequested;
+
+ protected override int VisualChildrenCount => _visuals.Count;
+ protected override Visual GetVisualChild(int index) => _visuals[index];
+
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ // 蒙层覆盖整个区域
+ _mask.Arrange(new Rect(finalSize));
+
+ // 内容初始位置在左侧外部
+ _content.Arrange(new Rect(-_content.DesiredSize.Width, 0,
+ _content.DesiredSize.Width, finalSize.Height));
+ return finalSize;
+ }
+
+ public void SlideIn(TimeSpan duration)
+ {
+ var transform = new TranslateTransform();
+ _content.RenderTransform = transform;
+
+ var animation = new DoubleAnimation
+ {
+ To = 0,
+ Duration = duration,
+ EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
+ };
+
+ transform.BeginAnimation(TranslateTransform.XProperty, animation);
+ }
+
+ public void SlideOut(TimeSpan duration, Action? onCompleted = null)
+ {
+ var transform = _content.RenderTransform as TranslateTransform;
+ if (transform == null) return;
+
+ var animation = new DoubleAnimation
+ {
+ To = -_content.DesiredSize.Width,
+ Duration = duration,
+ EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
+ };
+
+ if (onCompleted != null)
+ animation.Completed += (s, e) => onCompleted();
+
+ transform.BeginAnimation(TranslateTransform.XProperty, animation);
+ }
+ }
+
+ ///
+ /// 简化的抽屉管理器
+ ///
+ public static class DrawerManager
+ {
+ public static void ShowDrawer(UIElement parentElement, FrameworkElement drawerContent, double maskOpacity = 0.5)
+ {
+ var layer = AdornerLayer.GetAdornerLayer(parentElement);
+ if (layer == null) return;
+
+ var adorner = new SlideDrawerAdorner(parentElement, drawerContent, maskOpacity);
+ adorner.CloseRequested += (s, e) => HideDrawer(parentElement);
+
+ layer.Add(adorner);
+ adorner.SlideIn(TimeSpan.FromMilliseconds(300));
+ }
+
+ public static void HideDrawer(UIElement parentElement)
+ {
+ var layer = AdornerLayer.GetAdornerLayer(parentElement);
+ if (layer == null) return;
+
+ var adorners = layer.GetAdorners(parentElement);
+ if (adorners == null) return;
+
+ foreach (var adorner in adorners)
+ {
+ if (adorner is SlideDrawerAdorner slideAdorner)
+ {
+ slideAdorner.SlideOut(TimeSpan.FromMilliseconds(250), () =>
+ {
+ layer.Remove(slideAdorner);
+ });
+ break;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DeedyDesigner/Deedy.Testing/SlideViewer.cs b/DeedyDesigner/Deedy.Testing/SlideViewer.cs
new file mode 100644
index 0000000..9162467
--- /dev/null
+++ b/DeedyDesigner/Deedy.Testing/SlideViewer.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Documents;
+
+namespace Deedy.Testing
+{
+ public class SlideViewer : Adorner
+ {
+ public SlideViewer(UIElement adornedElement) : base(adornedElement)
+ {
+ //「AdornedElement」=「adornedElement」
+ }
+ }
+}