彻底确认采用OnRender方法重绘Panel子类的视觉效果是不可行的

This commit is contained in:
zengwenjie
2025-09-26 13:41:13 +08:00
parent d0bfabe9b0
commit c65972b1a9
5 changed files with 30 additions and 39 deletions

View File

@@ -7,11 +7,16 @@ using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace Deedy.Activity
{
public class VisualLayout : IVisualLayout
public class VisualLayout : Control, IVisualLayout
{
static VisualLayout()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(VisualLayout), new FrameworkPropertyMetadata(typeof(VisualLayout)));
}
public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping();
public VisualLayout() { }
public string Class { get; protected internal set; } = "";

View File

@@ -26,56 +26,45 @@ namespace Deedy.Activity.Helpers
public static void Help_DrawDropAdorner(this UIElement ui, DrawingContext dc, DropPlacement dropPlacement, LayoutDirection parentLayout)
{
if (ui == null || dc == null || dropPlacement == DropPlacement.UnDragged) return;
Pen pen = new Pen(Brushes.Red, 3);
Pen pen = new Pen(Brushes.Transparent, 0);
pen.Freeze();
Brush brush = new SolidColorBrush(Colors.Red) { Opacity = 0.5 };
Size size = ui.RenderSize;
ThemeResources res = new();
switch (dropPlacement)
{
case DropPlacement.Rejected:
{
}
dc.DrawGeometry(brush, pen, res.DropIcon_RejectDragDrop);
break;
case DropPlacement.Uncertain:
{
}
dc.DrawGeometry(brush, pen, res.DropIcon_LinkWithOneself);
break;
case DropPlacement.BeforeMe:
{
if (parentLayout == LayoutDirection.Horizontal)
{
}
dc.DrawRectangle(brush, pen, new(0, 0, 4, size.Height));
else if (parentLayout == LayoutDirection.Vertical)
{
}
dc.DrawRectangle(brush, pen, new(0, 0, size.Width, 4));
else if (parentLayout == LayoutDirection.Stacked)
{
}
else { }
dc.DrawGeometry(brush, pen, res.DropIcon_BringForward);
}
break;
case DropPlacement.BehindMe:
{
if (parentLayout == LayoutDirection.Horizontal)
{
}
dc.DrawRectangle(brush, pen, new(size.Width - 4, 0, 4, size.Height));
else if (parentLayout == LayoutDirection.Vertical)
{
}
dc.DrawRectangle(brush, pen, new(size.Height - 4, 0, size.Width, 4));
else if (parentLayout == LayoutDirection.Stacked)
{
}
else { }
dc.DrawGeometry(brush, pen, res.DropIcon_SendBackward);
}
break;
case DropPlacement.WithinMe:
{
}
dc.DrawGeometry(brush, pen, res.DropIcon_InsideOneself);
break;
case DropPlacement.ReplaceMe:
{
}
dc.DrawGeometry(brush, pen, res.DropIcon_ReplaceOneself);
break;
default: break; //DropPlacement.UnDragged;不需要绘制任何图样
}
@@ -96,7 +85,7 @@ namespace Deedy.Activity.Helpers
DropPlacement result = DropPlacement.UnDragged;
if (ui != null)
{
System.Windows.Size size = ui.RenderSize;
Size size = ui.RenderSize;
double horRuler = size.Width / 3;
if (horRuler > 20) horRuler = 20;
double verRuler = size.Height / 3;
@@ -171,10 +160,13 @@ namespace Deedy.Activity.Helpers
newGeometry.Transform = new TransformGroup
{
Children = {
new RotateTransform(angle,newGeometry.Bounds.Left + newGeometry.Bounds.Width/2,
newGeometry.Bounds.Top + newGeometry.Bounds.Height/2), // 顺时针旋转90度
new ScaleTransform(rectangle.Width/newGeometry.Bounds.Width, rectangle.Height/newGeometry.Bounds.Height), // 宽度放大2倍高度放大1.5倍
new TranslateTransform(rectangle.Left-newGeometry.Bounds.Left, rectangle.Top-newGeometry.Bounds.Top), // X/Y方向位移
new RotateTransform(angle, // 顺时针旋转
newGeometry.Bounds.Left + newGeometry.Bounds.Width/2, // X 方向旋转中心
newGeometry.Bounds.Top + newGeometry.Bounds.Height/2), // Y 方向旋转中心
new ScaleTransform(rectangle.Width/newGeometry.Bounds.Width, // X 方向缩放
rectangle.Height/newGeometry.Bounds.Height), // Y 方向缩放
new TranslateTransform(rectangle.Left-newGeometry.Bounds.Left, // X 方向位移
rectangle.Top-newGeometry.Bounds.Top), // Y 方向位移
}
};
return newGeometry;

View File

@@ -27,7 +27,6 @@ namespace Deedy.Activity
public const string DropIcon_BringForward = "DropIcon_BringForward"; // 上移一层
public const string DropIcon_SendBackward = "DropIcon_SendBackward"; // 下移一层
public const string DropIcon_InsideOneself = "DropIcon_InsideOneself"; // 自身内部
public const string DropIcon_BeforeOrBehind = "DropIcon_BeforeOrBehind"; // 自身前后
public const string DropIcon_ReplaceOneself = "DropIcon_ReplaceOneself"; // 替换自身
public const string DropIcon_LinkWithOneself = "DropIcon_LinkWithOneself"; // 链接自身
public const string DropIcon_RejectDragDrop = "DropIcon_RejectDragDrop"; // 决绝拖放
@@ -55,7 +54,6 @@ namespace Deedy.Activity
public static ComponentResourceKey DropIcon_BringForward = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_BringForward);
public static ComponentResourceKey DropIcon_SendBackward = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_SendBackward);
public static ComponentResourceKey DropIcon_InsideOneself = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_InsideOneself);
public static ComponentResourceKey DropIcon_BeforeOrBehind = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_BeforeOrBehind);
public static ComponentResourceKey DropIcon_ReplaceOneself = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_ReplaceOneself);
public static ComponentResourceKey DropIcon_LinkWithOneself = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_LinkWithOneself);
public static ComponentResourceKey DropIcon_RejectDragDrop = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_RejectDragDrop);

View File

@@ -25,7 +25,6 @@ namespace Deedy.Activity
public PathGeometry? DropIcon_BringForward => this[ThemeKeys.DropIcon_BringForward] as PathGeometry;
public PathGeometry? DropIcon_SendBackward => this[ThemeKeys.DropIcon_SendBackward] as PathGeometry;
public PathGeometry? DropIcon_InsideOneself => this[ThemeKeys.DropIcon_InsideOneself] as PathGeometry;
public PathGeometry? DropIcon_BeforeOrBehind => this[ThemeKeys.DropIcon_BeforeOrBehind] as PathGeometry;
public PathGeometry? DropIcon_ReplaceOneself => this[ThemeKeys.DropIcon_ReplaceOneself] as PathGeometry;
public PathGeometry? DropIcon_LinkWithOneself => this[ThemeKeys.DropIcon_LinkWithOneself] as PathGeometry;
public PathGeometry? DropIcon_RejectDragDrop => this[ThemeKeys.DropIcon_RejectDragDrop] as PathGeometry;

View File

@@ -70,13 +70,10 @@
M 11 0 V 10.5 H 13 V 0 Z M 0 10.5 L 12 15 L 24 10.5 L 16 7.5 A 1 1 0 0 0 16 9 L 20 10.5 L 12 13.5 L 4 10.5 L 8 9 A 1 1 0 0 0 8 7.5 z M 11 16.5 V 20.5 L 6.5 19 L 12 24 V 24 L 17.5 19 L 13 20.5 V 16.5 Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_InsideOneself}">
M0,0H8L16,16L0,8ZM16,16L24,0V24H0Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_BeforeOrBehind}">
M0,0H24V4H0ZM12,4L0,16L12,10L24,16ZM12,10L0,24L12,16L24,24Z
M 14 3 H 17 L 12 8 L 7 3 H 10 V 0 H 14 V 3 Z M 10 21 H 7 L 12 16 L 17 21 H 14 V 24 H 10 V 21 Z M 3 10 V 7 L 8 12 L 3 17 V 14 H 0 V 10 H 3 Z M 21 14 V 17 L 16 12 L 21 7 V 10 H 24 V 14 H 21 Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_ReplaceOneself}">
M0,24V0H24L6,6ZM6,6L12,24V12H24Z
M 23 12 c 0 1.042 -0.154 2.045 -0.425 3 h -2.101 c 0.335 -0.94 0.526 -1.947 0.526 -3 c 0 -4.962 -4.037 -9 -9 -9 c -1.706 0 -3.296 0.484 -4.655 1.314 l 1.858 2.686 h -6.994 l 2.152 -7 l 1.849 2.673 c 1.684 -1.049 3.659 -1.673 5.79 -1.673 c 6.074 0 11 4.925 11 11 z m -6.354 7.692 c -1.357 0.826 -2.944 1.308 -4.646 1.308 c -4.962 0 -9 -4.038 -9 -9 c 0 -1.053 0.191 -2.06 0.525 -3 h -2.1 c -0.271 0.955 -0.425 1.958 -0.425 3 c 0 6.075 4.925 11 11 11 c 2.127 0 4.099 -0.621 5.78 -1.667 l 1.853 2.667 l 2.152 -6.989 h -6.994 l 1.855 2.681 z m -3.646 -5.692 h -2 v -7 h 2 v 7 z m 0 1 h -2 v 2 h 2 v -2 z M 0 0 V 24 H 24 H 0
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_LinkWithOneself}">
M 21 9 C 19.344 9 18 10.343 18 12 S 19.344 15 21 15 S 24 13.657 24 12 S 22.656 9 21 9 Z M 6 18 C 4.343 18 3 19.343 3 21 S 4.343 24 6 24 C 7.656 24 9 22.657 9 21 S 7.656 18 6 18 Z M 9 3 C 9 4.657 7.656 6 6 6 S 3 4.657 3 3 S 4.344 0 6 0 S 9 1.343 9 3 Z M 10.588 1.021 L 11 1 C 15.281 1 18.981 3.45 20.8 7.021 C 20.083 7.05 19.41 7.231 18.802 7.532 C 17.247 4.829 14.336 3 11 3 C 11 2.297 10.851 1.628 10.588 1.021 Z M 20.8 16.979 C 18.981 20.55 15.281 23 11 23 L 10.588 22.979 C 10.851 22.372 11 21.703 11 21 C 14.336 21 17.247 19.171 18.802 16.468 C 19.41 16.77 20.083 16.951 20.8 16.979 Z M 1.89 18.165 C 0.697 16.406 0 14.285 0 12 S 0.697 7.594 1.89 5.835 C 2.282 6.401 2.791 6.874 3.377 7.238 C 2.51 8.621 2 10.25 2 12 S 2.51 15.379 3.377 16.762 C 2.791 17.126 2.281 17.599 1.89 18.165 Z