@@ -49,6 +49,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdateTwoFingerGestureBorderPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(TwoFingerGestureBorder);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardTwoFingerGestureBorder);
|
||||
}
|
||||
@@ -1712,6 +1713,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdateBorderToolsPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BorderTools);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardBorderTools);
|
||||
}
|
||||
@@ -2401,6 +2403,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdatePenPalettePosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(PenPalette);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardPenPalette);
|
||||
}
|
||||
@@ -2510,6 +2513,7 @@ namespace Ink_Canvas
|
||||
// 已是橡皮状态,再次点击才弹出/收起面板
|
||||
if (EraserSizePanel.Visibility == Visibility.Collapsed)
|
||||
{
|
||||
UpdateEraserSizePanelPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
if (BoardEraserSizePanel != null)
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
@@ -2560,6 +2564,7 @@ namespace Ink_Canvas
|
||||
// 已是橡皮状态,再次点击才弹出/收起面板
|
||||
if (BoardEraserSizePanel != null && BoardEraserSizePanel.Visibility == Visibility.Collapsed)
|
||||
{
|
||||
UpdateEraserSizePanelPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
}
|
||||
@@ -4161,6 +4166,101 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用子面板位置更新方法:根据触发按钮的位置,动态调整子面板的水平位置,
|
||||
/// 使面板水平中心对齐按钮中心。不改变面板大小,不改变上下边距。
|
||||
/// </summary>
|
||||
/// <param name="button">触发按钮元素</param>
|
||||
/// <param name="panel">需要定位的子面板</param>
|
||||
/// <param name="defaultPanelWidth">面板默认宽度(当无法从Margin计算时使用)</param>
|
||||
private void UpdateSubPanelPosition(FrameworkElement button, FrameworkElement panel, double defaultPanelWidth)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (button == null || panel == null) return;
|
||||
if (!(panel.Parent is FrameworkElement panelContainer)) return;
|
||||
|
||||
var ancestor = StackPanelFloatingBar;
|
||||
if (ancestor == null) return;
|
||||
|
||||
// 获取按钮中心的X坐标(相对于 StackPanelFloatingBar 坐标系)
|
||||
var buttonTransform = button.TransformToAncestor(ancestor);
|
||||
var buttonOrigin = buttonTransform.Transform(new Point(0, 0));
|
||||
double buttonCenterX = buttonOrigin.X + button.ActualWidth / 2.0;
|
||||
|
||||
// 获取面板容器(零宽度Grid)的X坐标(相对于 StackPanelFloatingBar 坐标系)
|
||||
var containerTransform = panelContainer.TransformToAncestor(ancestor);
|
||||
var containerOrigin = containerTransform.Transform(new Point(0, 0));
|
||||
double containerX = containerOrigin.X;
|
||||
|
||||
// 计算当前面板宽度(保持不变):panelWidth = -Margin.Left - Margin.Right
|
||||
double currentLeft = panel.Margin.Left;
|
||||
double currentRight = panel.Margin.Right;
|
||||
double panelWidth = -currentLeft - currentRight;
|
||||
if (panelWidth <= 0) panelWidth = defaultPanelWidth;
|
||||
|
||||
// 计算新的左边距,使面板水平中心对齐按钮:
|
||||
// panel_center = containerX + newLeft + panelWidth/2 = buttonCenterX
|
||||
// => newLeft = buttonCenterX - containerX - panelWidth/2
|
||||
double newLeft = buttonCenterX - containerX - panelWidth / 2.0;
|
||||
|
||||
// 保持面板宽度不变:-newLeft - newRight = panelWidth
|
||||
// => newRight = -panelWidth - newLeft
|
||||
double newRight = -panelWidth - newLeft;
|
||||
|
||||
// 清除可能残留的 Margin 动画(HoldEnd 会阻止本地值生效)
|
||||
panel.BeginAnimation(FrameworkElement.MarginProperty, null);
|
||||
|
||||
// 更新边距,仅调整Left/Right,保持Top/Bottom不变
|
||||
var margin = panel.Margin;
|
||||
panel.Margin = new Thickness(newLeft, margin.Top, newRight, margin.Bottom);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新子面板位置失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新批注子面板(PenPalette)的弹出位置,使其水平中心对齐笔按钮。
|
||||
/// </summary>
|
||||
private void UpdatePenPalettePosition()
|
||||
{
|
||||
UpdateSubPanelPosition(Pen_Icon, PenPalette, 193);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新工具面板(BorderTools)的弹出位置,使其水平中心对齐工具按钮。
|
||||
/// </summary>
|
||||
private void UpdateBorderToolsPosition()
|
||||
{
|
||||
UpdateSubPanelPosition(ToolsFloatingBarBtn, BorderTools, 119);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新橡皮擦尺寸面板(EraserSizePanel)的弹出位置,使其水平中心对齐橡皮擦按钮。
|
||||
/// </summary>
|
||||
private void UpdateEraserSizePanelPosition()
|
||||
{
|
||||
UpdateSubPanelPosition(Eraser_Icon, EraserSizePanel, 120);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新形状绘制面板(BorderDrawShape)的弹出位置,使其水平中心对齐形状按钮。
|
||||
/// </summary>
|
||||
private void UpdateBorderDrawShapePosition()
|
||||
{
|
||||
UpdateSubPanelPosition(ShapeDrawFloatingBarBtn, BorderDrawShape, 317);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新手势面板(TwoFingerGestureBorder)的弹出位置,使其水平中心对齐手势按钮。
|
||||
/// </summary>
|
||||
private void UpdateTwoFingerGestureBorderPosition()
|
||||
{
|
||||
UpdateSubPanelPosition(EnableTwoFingerGestureBorder, TwoFingerGestureBorder, 119);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏浮动栏高光显示
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user