mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-02 07:06:37 +08:00
内部基础ZoomBox
This commit is contained in:
@@ -1900,6 +1900,7 @@
|
||||
Width="180"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom"
|
||||
OffSet="True"
|
||||
DesignerCanvas="{Binding ElementName=diagram}"
|
||||
MaximumZoomValue="{Binding MaximumZoomValue,Mode=TwoWay}"
|
||||
MinimumZoomValue="{Binding MinimumZoomValue,Mode=TwoWay}"
|
||||
|
||||
@@ -13,10 +13,9 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
|
||||
Info = "Drag the upper-right scroll bar to make the canvas larger and smaller.";
|
||||
|
||||
DiagramViewModel = new DiagramViewModel();
|
||||
DiagramViewModel.PageSizeType = PageSizeType.Custom;
|
||||
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
|
||||
DiagramViewModel.ColorViewModel = new ColorViewModel();
|
||||
DiagramViewModel.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
|
||||
DiagramViewModel.DefaultZoomBox = true;
|
||||
|
||||
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 50, Top = 50, Text = "1" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node1);
|
||||
|
||||
@@ -11,19 +11,6 @@
|
||||
<!-- Diagram Control -->
|
||||
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
|
||||
|
||||
<Slider x:Name="zoomSlider"
|
||||
Minimum="0.5"
|
||||
Value="{Binding DiagramViewModel.ZoomValue}"
|
||||
Maximum="2.0"
|
||||
IsDirectionReversed="False"
|
||||
IsSnapToTickEnabled="True"
|
||||
TickFrequency="0.1"
|
||||
SmallChange="0.1"
|
||||
LargeChange="0.1"
|
||||
Width="200"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"/>
|
||||
|
||||
<controls:TitleControl/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -56,25 +56,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ZoomValueProperty = DependencyProperty.Register(nameof(ZoomValue), typeof(double), typeof(DiagramControl), new UIPropertyMetadata(1d));
|
||||
public double ZoomValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return (double)GetValue(ZoomValueProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(ZoomValueProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void DesignerCanvas_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//DesignerCanvas myDesignerCanvas = sender as DesignerCanvas;
|
||||
//zoomBox.DesignerCanvas = myDesignerCanvas;
|
||||
}
|
||||
|
||||
private IDiagramViewModel DiagramViewModel
|
||||
{
|
||||
get
|
||||
|
||||
@@ -428,6 +428,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _defaultZoomBox;
|
||||
public bool DefaultZoomBox
|
||||
{
|
||||
get
|
||||
{
|
||||
return _defaultZoomBox;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _defaultZoomBox, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _delayZoomValue = 1;
|
||||
[Browsable(false)]
|
||||
public double DelayZoomValue
|
||||
|
||||
@@ -265,6 +265,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool DefaultZoomBox
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool AllowDrop
|
||||
{
|
||||
get; set;
|
||||
|
||||
Reference in New Issue
Block a user