mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-02 23:26:35 +08:00
Revert "Revert "block 可以拖拽到内部,还有少量问题待解决""
This reverts commit fcd7beb193.
This commit is contained in:
114
Extensions/AIStudio.Wpf.Block/Controls/BlockDecorator.cs
Normal file
114
Extensions/AIStudio.Wpf.Block/Controls/BlockDecorator.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.Block.Controls
|
||||
{
|
||||
public class BlockDecorator : Decorator
|
||||
{
|
||||
#region 依赖属性
|
||||
public static readonly DependencyProperty BackgroundProperty =
|
||||
DependencyProperty.Register(nameof(Background), typeof(Brush), typeof(BlockDecorator)
|
||||
, new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 255, 255))));
|
||||
/// <summary>
|
||||
/// 背景色,默认值为#FFFFFF,白色
|
||||
/// </summary>
|
||||
public Brush Background
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Brush)GetValue(BackgroundProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(BackgroundProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PaddingProperty =
|
||||
DependencyProperty.Register(nameof(Padding), typeof(Thickness), typeof(BlockDecorator)
|
||||
, new PropertyMetadata(new Thickness(0, 0, 0, 0)));
|
||||
/// <summary>
|
||||
/// 内边距
|
||||
/// </summary>
|
||||
public Thickness Padding
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Thickness)GetValue(PaddingProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(PaddingProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderBrushProperty =
|
||||
DependencyProperty.Register(nameof(BorderBrush), typeof(Brush), typeof(BlockDecorator)
|
||||
, new PropertyMetadata(default(Brush)));
|
||||
/// <summary>
|
||||
/// 边框颜色
|
||||
/// </summary>
|
||||
public Brush BorderBrush
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Brush)GetValue(BorderBrushProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(BorderBrushProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BorderThicknessProperty =
|
||||
DependencyProperty.Register(nameof(BorderThickness), typeof(Thickness), typeof(BlockDecorator), new PropertyMetadata(new Thickness(0d)));
|
||||
/// <summary>
|
||||
/// 边框大小
|
||||
/// </summary>
|
||||
public Thickness BorderThickness
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Thickness)GetValue(BorderThicknessProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(BorderThicknessProperty, value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
|
||||
{
|
||||
Point hitPoint = hitTestParameters.HitPoint;
|
||||
|
||||
// 在此处实现自定义的命中测试逻辑
|
||||
if (IsPointInsideCustomRegion(hitPoint))
|
||||
{
|
||||
return new PointHitTestResult(this, hitPoint);
|
||||
}
|
||||
|
||||
return null; // 不命中
|
||||
}
|
||||
|
||||
private bool IsPointInsideCustomRegion(Point point)
|
||||
{
|
||||
// 在此处检测点是否在自定义区域内
|
||||
// 返回 true 表示命中,返回 false 表示不命中
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Brush CreateFillBrush()
|
||||
{
|
||||
Brush result = null;
|
||||
|
||||
System.Windows.Media.GradientStopCollection gsc = new System.Windows.Media.GradientStopCollection();
|
||||
gsc.Add(new System.Windows.Media.GradientStop(((SolidColorBrush)this.Background).Color, 0));
|
||||
LinearGradientBrush backGroundBrush = new LinearGradientBrush(gsc, new Point(0, 0), new Point(0, 1));
|
||||
result = backGroundBrush;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user