mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
115 lines
3.6 KiB
C#
115 lines
3.6 KiB
C#
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Media;
|
||
|
||
namespace AIStudio.Wpf.Block.Controls
|
||
{
|
||
public class BlockPanel : Panel
|
||
{
|
||
#region 依赖属性
|
||
public static readonly DependencyProperty BackgroundProperty =
|
||
DependencyProperty.Register(nameof(Background), typeof(Brush), typeof(BlockPanel)
|
||
, 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(BlockPanel)
|
||
, 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(BlockPanel)
|
||
, 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(BlockPanel), 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;
|
||
}
|
||
}
|
||
}
|