mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-03 07:36:35 +08:00
内部基础ZoomBox
This commit is contained in:
@@ -80,6 +80,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
#endregion
|
||||
|
||||
public static readonly DependencyProperty OffSetProperty =
|
||||
DependencyProperty.Register(nameof(OffSet), typeof(bool), typeof(ZoomBox), new UIPropertyMetadata(false));
|
||||
public bool OffSet
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bool)GetValue(OffSetProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(OffSetProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ZoomValueProperty =
|
||||
DependencyProperty.Register(nameof(ZoomValue), typeof(double), typeof(ZoomBox), new UIPropertyMetadata(1d));
|
||||
public double ZoomValue
|
||||
@@ -200,18 +214,36 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void InvalidateScale(out double scale, out double xOffset, out double yOffset)
|
||||
{
|
||||
Vector vector = System.Windows.Media.VisualTreeHelper.GetOffset(DesignerCanvas);
|
||||
double w = DesignerCanvas.ActualWidth + vector.X * 2;
|
||||
double h = DesignerCanvas.ActualHeight + vector.Y * 2;
|
||||
if (OffSet)
|
||||
{
|
||||
Vector vector = System.Windows.Media.VisualTreeHelper.GetOffset(DesignerCanvas);
|
||||
double w = DesignerCanvas.ActualWidth + vector.X * 2;
|
||||
double h = DesignerCanvas.ActualHeight + vector.Y * 2;
|
||||
|
||||
// zoom canvas size
|
||||
double x = this.zoomCanvas.ActualWidth;
|
||||
double y = this.zoomCanvas.ActualHeight;
|
||||
double scaleX = x / w;
|
||||
double scaleY = y / h;
|
||||
scale = (scaleX < scaleY) ? scaleX : scaleY;
|
||||
xOffset = (x - scale * w) / 2;
|
||||
yOffset = (y - scale * h) / 2;
|
||||
// zoom canvas size
|
||||
double x = this.zoomCanvas.ActualWidth;
|
||||
double y = this.zoomCanvas.ActualHeight;
|
||||
double scaleX = x / w;
|
||||
double scaleY = y / h;
|
||||
scale = (scaleX < scaleY) ? scaleX : scaleY;
|
||||
xOffset = (x - scale * w) / 2;
|
||||
yOffset = (y - scale * h) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
double w = DesignerCanvas.ActualWidth;
|
||||
double h = DesignerCanvas.ActualHeight;
|
||||
|
||||
// zoom canvas size
|
||||
double x = this.zoomCanvas.ActualWidth;
|
||||
double y = this.zoomCanvas.ActualHeight;
|
||||
double scaleX = x / w;
|
||||
double scaleY = y / h;
|
||||
scale = (scaleX < scaleY) ? scaleX : scaleY;
|
||||
xOffset = (x - scale * w) / 2;
|
||||
yOffset = (y - scale * h) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user