mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-02 15:50:51 +08:00
页边距修改
This commit is contained in:
@@ -85,7 +85,21 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
public PageSizeType PageSizeType { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public double GridMargin { get; set; }
|
||||
public Size GridMarginSize { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlAttribute("GridMarginSize")]
|
||||
public string XmlGridMarginSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return SerializeHelper.SerializeSize(GridMarginSize);
|
||||
}
|
||||
set
|
||||
{
|
||||
GridMarginSize = SerializeHelper.DeserializeSize(value);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public Color GridColor { get; set; }
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation;
|
||||
viewModel.PageSize = diagramItem.PageSize;
|
||||
viewModel.PageSizeType = diagramItem.PageSizeType;
|
||||
viewModel.GridMargin = diagramItem.GridMargin;
|
||||
viewModel.GridMarginSize = diagramItem.GridMarginSize;
|
||||
viewModel.GridColor = diagramItem.GridColor;
|
||||
|
||||
foreach (DesignerItemBase diagramItemData in diagramItem.AllDesignerItems)
|
||||
@@ -321,7 +321,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
diagramItem.PageSizeOrientation = viewModel.PageSizeOrientation;
|
||||
diagramItem.PageSize = viewModel.PageSize;
|
||||
diagramItem.PageSizeType = viewModel.PageSizeType;
|
||||
diagramItem.GridMargin = viewModel.GridMargin;
|
||||
diagramItem.GridMarginSize = viewModel.GridMarginSize;
|
||||
diagramItem.GridColor = viewModel.GridColor;
|
||||
|
||||
diagramItem.AddItems(DiagramViewModel.Items);
|
||||
@@ -496,7 +496,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
diagramItem.PageSizeOrientation = viewModel.PageSizeOrientation;
|
||||
diagramItem.PageSize = viewModel.PageSize;
|
||||
diagramItem.PageSizeType = viewModel.PageSizeType;
|
||||
diagramItem.GridMargin = viewModel.GridMargin;
|
||||
diagramItem.GridMarginSize = viewModel.GridMarginSize;
|
||||
diagramItem.GridColor = viewModel.GridColor;
|
||||
|
||||
diagramItem.AddItems(DiagramViewModel.Items);
|
||||
@@ -523,7 +523,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation;
|
||||
viewModel.PageSize = diagramItem.PageSize;
|
||||
viewModel.PageSizeType = diagramItem.PageSizeType;
|
||||
viewModel.GridMargin = diagramItem.GridMargin;
|
||||
viewModel.GridMarginSize = diagramItem.GridMarginSize;
|
||||
viewModel.GridColor = diagramItem.GridColor;
|
||||
|
||||
foreach (DesignerItemBase diagramItemData in diagramItem.AllDesignerItems)
|
||||
|
||||
@@ -1518,7 +1518,13 @@
|
||||
<TextBlock Margin="5" Text="高度" VerticalAlignment="Center"/>
|
||||
<Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridCellHeight,Mode=TwoWay}" Minimum="0" Format="0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Margin="5" Text="左右边距" VerticalAlignment="Center"/>
|
||||
<Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridMarginWidth,Mode=TwoWay}" Minimum="0" Format="0" />
|
||||
<TextBlock Margin="5" Text="上下边距" VerticalAlignment="Center"/>
|
||||
<Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridMarginHeight,Mode=TwoWay}" Minimum="0" Format="0" />
|
||||
</StackPanel>
|
||||
|
||||
<Fluent:SplitButton.ToolTip>
|
||||
<Fluent:ScreenTip Title="ShowGrid"
|
||||
Text="显示网格"
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
|
||||
DiagramViewModel = new DiagramViewModel();
|
||||
DiagramViewModel.ShowGrid = true;
|
||||
DiagramViewModel.GridCellSize = new Size(100, 100);
|
||||
DiagramViewModel.GridMargin = 0d;
|
||||
DiagramViewModel.GridMarginSize = new Size(0, 0);
|
||||
DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
|
||||
DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
|
||||
DiagramViewModel.PageSizeType = PageSizeType.Custom;
|
||||
|
||||
@@ -102,18 +102,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
#endregion
|
||||
|
||||
#region GridMargin 单位mm
|
||||
#region GridMarginSize 单位mm
|
||||
|
||||
public static readonly DependencyProperty GridMarginProperty =
|
||||
DependencyProperty.Register(nameof(GridMargin),
|
||||
typeof(double),
|
||||
public static readonly DependencyProperty GridMarginSizeProperty =
|
||||
DependencyProperty.Register(nameof(GridMarginSize),
|
||||
typeof(Size),
|
||||
typeof(DesignerCanvas),
|
||||
new FrameworkPropertyMetadata(28d, FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
new FrameworkPropertyMetadata(new Size(28, 28), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public double GridMargin
|
||||
public Size GridMarginSize
|
||||
{
|
||||
get { return (double)GetValue(GridMarginProperty); }
|
||||
set { SetValue(GridMarginProperty, value); }
|
||||
get { return (Size)GetValue(GridMarginSizeProperty); }
|
||||
set { SetValue(GridMarginSizeProperty, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -137,13 +137,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected virtual void DrawGrid(DrawingContext dc, Rect rect)
|
||||
{
|
||||
//using .5 forces wpf to draw a single pixel line
|
||||
for (var i = GridMargin + 0.5; i < rect.Height - GridMargin; i += GridCellSize.Height)
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMargin, i), new Point(rect.Width - GridMargin, i));
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMargin, rect.Height - GridMargin), new Point(rect.Width - GridMargin, rect.Height - GridMargin));
|
||||
for (var i = GridMarginSize.Height + 0.5; i < rect.Height - GridMarginSize.Height; i += GridCellSize.Height)
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMarginSize.Width, i), new Point(rect.Width - GridMarginSize.Width, i));
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMarginSize.Width, rect.Height - GridMarginSize.Height), new Point(rect.Width - GridMarginSize.Width, rect.Height - GridMarginSize.Height));
|
||||
|
||||
for (var i = GridMargin + 0.5; i < rect.Width - GridMargin; i += GridCellSize.Width)
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(i, GridMargin), new Point(i, rect.Height - GridMargin));
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(rect.Width - GridMargin, GridMargin), new Point(rect.Width - GridMargin, rect.Height - GridMargin));
|
||||
for (var i = GridMarginSize.Width + 0.5; i < rect.Width - GridMarginSize.Width; i += GridCellSize.Width)
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(i, GridMarginSize.Height), new Point(i, rect.Height - GridMarginSize.Height));
|
||||
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(rect.Width - GridMarginSize.Width, GridMarginSize.Height), new Point(rect.Width - GridMarginSize.Width, rect.Height - GridMarginSize.Height));
|
||||
}
|
||||
|
||||
private void _service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
link.SinkConnectorInfo.MiddlePosition,
|
||||
link.IsFullConnection ? link.SinkConnectorInfoFully.Orientation : (link.SinkConnectorInfo.MiddlePosition.Y >= link.SourceConnectorInfo.MiddlePosition.Y ? ConnectorOrientation.Top : ConnectorOrientation.Bottom),
|
||||
_.GridCellSize,
|
||||
_.GridMargin);
|
||||
_.GridMarginSize);
|
||||
|
||||
middle.Insert(0, route[0]);
|
||||
middle.Add(route[1]);
|
||||
@@ -46,7 +46,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return middle.ToArray();
|
||||
}
|
||||
|
||||
private static List<PointBase> GetMiddlePoints(PointBase source, ConnectorOrientation sourceOrientation, PointBase sink, ConnectorOrientation sinkOrientation, SizeBase gridCellSize, double gridMargin)
|
||||
private static List<PointBase> GetMiddlePoints(PointBase source, ConnectorOrientation sourceOrientation, PointBase sink, ConnectorOrientation sinkOrientation, SizeBase gridCellSize, SizeBase gridMargin)
|
||||
{
|
||||
var points = new List<PointBase>();
|
||||
|
||||
@@ -56,8 +56,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (p0 == p1)
|
||||
return points;
|
||||
|
||||
var p2 = new PointBase(GetNearestCross(p0.X, p1.X, gridCellSize.Width, gridMargin), GetNearestCross(p0.Y, p1.Y, gridCellSize.Height, gridMargin));
|
||||
var p3 = new PointBase(GetNearestCross(p1.X, p0.X, gridCellSize.Width, gridMargin), GetNearestCross(p1.Y, p0.Y, gridCellSize.Height, gridMargin));
|
||||
var p2 = new PointBase(GetNearestCross(p0.X, p1.X, gridCellSize.Width, gridMargin.Width), GetNearestCross(p0.Y, p1.Y, gridCellSize.Height, gridMargin.Height));
|
||||
var p3 = new PointBase(GetNearestCross(p1.X, p0.X, gridCellSize.Width, gridMargin.Width), GetNearestCross(p1.Y, p0.Y, gridCellSize.Height, gridMargin.Height));
|
||||
if (p2 == p3)
|
||||
{
|
||||
points.Add(p0);
|
||||
@@ -77,10 +77,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return points;
|
||||
}
|
||||
|
||||
private static PointBase GetFirstSegment(PointBase point, ConnectorOrientation orientation, SizeBase cellSize, double margin)
|
||||
private static PointBase GetFirstSegment(PointBase point, ConnectorOrientation orientation, SizeBase cellSize, SizeBase margin)
|
||||
{
|
||||
double x = ((int)((point.X - margin) / cellSize.Width) + 0.5) * cellSize.Width + margin;
|
||||
double y = ((int)((point.Y - margin) / cellSize.Height) + 0.5) * cellSize.Height + margin;
|
||||
double x = ((int)((point.X - margin.Width) / cellSize.Width) + 0.5) * cellSize.Width + margin.Width;
|
||||
double y = ((int)((point.Y - margin.Height) / cellSize.Height) + 0.5) * cellSize.Height + margin.Height;
|
||||
if (orientation == ConnectorOrientation.Top)
|
||||
return new PointBase(x, y - 0.5 * cellSize.Height);
|
||||
else if (orientation == ConnectorOrientation.Bottom)
|
||||
|
||||
@@ -942,7 +942,7 @@
|
||||
Width="{Binding PageSize.Width}"
|
||||
ShowGrid="{Binding ShowGrid}"
|
||||
GridCellSize="{Binding GridCellSize}"
|
||||
GridMargin="{Binding GridMargin}"
|
||||
GridMarginSize="{Binding GridMarginSize}"
|
||||
GridColor="{Binding GridColor}"
|
||||
Background="{Binding PageBackground,Converter={StaticResource ColorBrushConverter}}"
|
||||
AllowDrop="True">
|
||||
|
||||
@@ -387,18 +387,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (Root.GridCellSize.Width > this.ItemWidth)
|
||||
{
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin + (Root.GridCellSize.Width - this.ItemWidth) / 2;
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMarginSize.Width + (Root.GridCellSize.Width - this.ItemWidth) / 2;
|
||||
}
|
||||
}
|
||||
else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Left)
|
||||
{
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin;
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMarginSize.Width;
|
||||
}
|
||||
else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Right)
|
||||
{
|
||||
if (Root.GridCellSize.Width > this.ItemWidth)
|
||||
{
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin + (Root.GridCellSize.Width - this.ItemWidth);
|
||||
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMarginSize.Width + (Root.GridCellSize.Width - this.ItemWidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,18 +406,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (Root.GridCellSize.Height > this.ItemHeight)
|
||||
{
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin + (Root.GridCellSize.Height - this.ItemHeight) / 2;
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMarginSize.Height + (Root.GridCellSize.Height - this.ItemHeight) / 2;
|
||||
}
|
||||
}
|
||||
else if (Root.CellVerticalAlignment == CellVerticalAlignment.Top)
|
||||
{
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin;
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMarginSize.Height;
|
||||
}
|
||||
else if (Root.CellVerticalAlignment == CellVerticalAlignment.Bottom)
|
||||
{
|
||||
if (Root.GridCellSize.Height > this.ItemHeight)
|
||||
{
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin + (Root.GridCellSize.Height - this.ItemHeight);
|
||||
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMarginSize.Height + (Root.GridCellSize.Height - this.ItemHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,8 +227,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private double _gridMargin = 28d;
|
||||
public double GridMargin
|
||||
private Size _gridMargin = new Size(28, 28);
|
||||
public Size GridMarginSize
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -240,6 +240,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public double GridMarginWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gridMargin.Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
_gridMargin.Width = value;
|
||||
RaisePropertyChanged(nameof(GridMarginSize));
|
||||
}
|
||||
}
|
||||
|
||||
public double GridMarginHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gridMargin.Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
_gridMargin.Height = value;
|
||||
RaisePropertyChanged(nameof(GridMarginSize));
|
||||
}
|
||||
}
|
||||
|
||||
private double _zoomValue = 1;
|
||||
[Browsable(false)]
|
||||
public double ZoomValue
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double GridMargin
|
||||
Size GridMarginSize
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace AIStudio.Wpf.Flowchart.Controls
|
||||
_diagramViewModel.SetScreenScale();
|
||||
_diagramViewModel.ShowGrid = true;
|
||||
_diagramViewModel.GridCellSize = new SizeBase(125 / _diagramViewModel.ScreenScale, 125 / _diagramViewModel.ScreenScale);
|
||||
_diagramViewModel.GridMargin = 0d;
|
||||
_diagramViewModel.GridMarginSize = new Size(0, 0);
|
||||
_diagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
|
||||
_diagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
|
||||
_diagramViewModel.PageSizeType = PageSizeType.Custom;
|
||||
|
||||
Reference in New Issue
Block a user