Revert "Revert "block 可以拖拽到内部,还有少量问题待解决""

This reverts commit fcd7beb193.
This commit is contained in:
艾竹
2023-06-11 23:58:22 +08:00
parent fcd7beb193
commit 5a9bcc03f3
73 changed files with 7132 additions and 242 deletions

View File

@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner
{
public static class WidthAndHeightProps
{
public static readonly DependencyProperty ActiveProperty = DependencyProperty.RegisterAttached(
"Active",
typeof(bool),
typeof(WidthAndHeightProps),
new FrameworkPropertyMetadata(OnActiveChanged));
public static bool GetActive(FrameworkElement frameworkElement)
{
return (bool)frameworkElement.GetValue(ActiveProperty);
}
public static void SetActive(FrameworkElement frameworkElement, bool active)
{
frameworkElement.SetValue(ActiveProperty, active);
}
public static readonly DependencyProperty BoundActualWidthProperty = DependencyProperty.RegisterAttached(
"BoundActualWidth",
typeof(double),
typeof(WidthAndHeightProps));
public static double GetBoundActualWidth(FrameworkElement frameworkElement)
{
return (double)frameworkElement.GetValue(BoundActualWidthProperty);
}
public static void SetBoundActualWidth(FrameworkElement frameworkElement, double width)
{
frameworkElement.SetValue(BoundActualWidthProperty, width);
}
public static readonly DependencyProperty BoundActualHeightProperty = DependencyProperty.RegisterAttached(
"BoundActualHeight",
typeof(double),
typeof(WidthAndHeightProps));
public static double GetBoundActualHeight(FrameworkElement frameworkElement)
{
return (double)frameworkElement.GetValue(BoundActualHeightProperty);
}
public static void SetBoundActualHeight(FrameworkElement frameworkElement, double height)
{
frameworkElement.SetValue(BoundActualHeightProperty, height);
}
private static void OnActiveChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (!(dependencyObject is FrameworkElement frameworkElement))
{
return;
}
if ((bool)e.NewValue)
{
frameworkElement.SizeChanged -= OnFrameworkElementSizeChanged;
frameworkElement.SizeChanged += OnFrameworkElementSizeChanged;
frameworkElement.Loaded -= FrameworkElement_Loaded;
frameworkElement.Loaded += FrameworkElement_Loaded;
}
else
{
frameworkElement.SizeChanged -= OnFrameworkElementSizeChanged;
frameworkElement.Loaded -= FrameworkElement_Loaded;
}
}
private static void FrameworkElement_Loaded(object sender, RoutedEventArgs e)
{
UpdateObservedSizesForFrameworkElement(sender as FrameworkElement);
}
private static void OnFrameworkElementSizeChanged(object sender, SizeChangedEventArgs e)
{
if (sender is FrameworkElement frameworkElement)
{
UpdateObservedSizesForFrameworkElement(frameworkElement);
}
}
private static void UpdateObservedSizesForFrameworkElement(FrameworkElement frameworkElement)
{
frameworkElement.SetCurrentValue(BoundActualWidthProperty, frameworkElement.ActualWidth);
frameworkElement.SetCurrentValue(BoundActualHeightProperty, frameworkElement.ActualHeight);
}
}
}