From b0aff1e37879c47dfba83a09a8921b08742b141c Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Fri, 1 May 2026 00:07:18 +0800 Subject: [PATCH] improve:UI --- Ink Canvas/App.xaml.cs | 2 +- Ink Canvas/MainWindow_cs/MW_PPT.cs | 144 ++++++++++++++++++++++------- 2 files changed, 110 insertions(+), 36 deletions(-) diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index d75d8b58..15d72943 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -283,7 +283,7 @@ namespace Ink_Canvas RegisterMainWindowDestroyHook(); } - catch (Exception ex) + catch (Exception) { } } diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index 4519f633..06bd1916 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -2436,24 +2436,35 @@ namespace Ink_Canvas if (anchor != null) { _pptEnhancedPreviewPopup.PlacementTarget = anchor; - if (anchor == PPTLBPageButton || anchor == PPTRBPageButton) + _pptEnhancedPreviewPopup.HorizontalOffset = 0; + _pptEnhancedPreviewPopup.VerticalOffset = 0; + + var anchorRef = anchor; + _pptEnhancedPreviewPopup.CustomPopupPlacementCallback = (popupSize, targetSize, _) => { - _pptEnhancedPreviewPopup.Placement = PlacementMode.Top; - _pptEnhancedPreviewPopup.HorizontalOffset = 0; - _pptEnhancedPreviewPopup.VerticalOffset = -10; - } - else if (anchor == PPTRSPageButton) - { - _pptEnhancedPreviewPopup.Placement = PlacementMode.Left; - _pptEnhancedPreviewPopup.HorizontalOffset = -12; - _pptEnhancedPreviewPopup.VerticalOffset = 0; - } - else - { - _pptEnhancedPreviewPopup.Placement = PlacementMode.Right; - _pptEnhancedPreviewPopup.HorizontalOffset = 12; - _pptEnhancedPreviewPopup.VerticalOffset = 0; - } + System.Windows.Point pt; + PopupPrimaryAxis axis; + if (anchorRef == PPTLBPageButton || anchorRef == PPTRBPageButton) + { + // 底部翻页按钮:弹窗位于按钮上方,水平居中 + pt = new System.Windows.Point((targetSize.Width - popupSize.Width) / 2, -popupSize.Height); + axis = PopupPrimaryAxis.Horizontal; + } + else if (anchorRef == PPTRSPageButton) + { + // 右侧翻页按钮:弹窗位于按钮左侧,底边与按钮底边对齐(向上展开) + pt = new System.Windows.Point(-popupSize.Width, targetSize.Height - popupSize.Height); + axis = PopupPrimaryAxis.Vertical; + } + else + { + // 左侧翻页按钮(默认):弹窗位于按钮右侧,底边与按钮底边对齐 + pt = new System.Windows.Point(targetSize.Width, targetSize.Height - popupSize.Height); + axis = PopupPrimaryAxis.Vertical; + } + return new[] { new CustomPopupPlacement(pt, axis) }; + }; + _pptEnhancedPreviewPopup.Placement = PlacementMode.Custom; } _pptEnhancedPreviewPopup.IsOpen = true; @@ -2494,45 +2505,112 @@ namespace Ink_Canvas var listBox = new ListBox { - Width = 220, - Height = 320, + Width = 248, + MaxHeight = 560, Background = Brushes.Transparent, BorderBrush = Brushes.Transparent, BorderThickness = new Thickness(0), + Padding = new Thickness(6, 4, 6, 8), SelectionMode = SelectionMode.Single }; - listBox.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden); + listBox.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); listBox.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); listBox.MouseUp += PPTEnhancedPreviewListBox_OnMouseUp; var templateXaml = @" - - - - - - + + + + + + + + + + + + + + + + + + - + "; listBox.ItemTemplate = (DataTemplate)XamlReader.Parse(templateXaml); + var itemStyleXaml = @" "; listBox.ItemContainerStyle = (Style)XamlReader.Parse(itemStyleXaml); + var headerXaml = @" + + + + + +"; + var header = (Border)XamlReader.Parse(headerXaml); + var headerGrid = (Grid)header.Child; + ((TextBlock)headerGrid.Children[0]).Text = "幻灯片预览"; + var countText = (TextBlock)headerGrid.Children[1]; + listBox.Loaded += (s, e) => + { + var items = listBox.ItemsSource as System.Collections.IList; + countText.Text = items != null ? $"共 {items.Count} 页" : string.Empty; + }; + + var rootXaml = @" + + + + + +"; + var rootBorder = (Border)XamlReader.Parse(rootXaml); + var dock = (DockPanel)rootBorder.Child; + DockPanel.SetDock(header, Dock.Top); + dock.Children.Add(header); + dock.Children.Add(listBox); + _pptEnhancedPreviewListBox = listBox; _pptEnhancedPreviewPopup = new Popup { @@ -2540,7 +2618,7 @@ namespace Ink_Canvas StaysOpen = true, Placement = PlacementMode.Right, PopupAnimation = PopupAnimation.Fade, - Child = listBox + Child = rootBorder }; } @@ -2549,11 +2627,7 @@ namespace Ink_Canvas if (_pptEnhancedPreviewListBox?.SelectedItem is not PptEnhancedPreviewItem item) return; try { - if (_pptManager?.TryNavigateToSlide(item.SlideNumber) == true) - { - LogHelper.WriteLogToFile($"PPT增强预览跳转成功:{item.SlideNumber}", LogHelper.LogType.Trace); - } - else + if (_pptManager?.TryNavigateToSlide(item.SlideNumber) != true) { LogHelper.WriteLogToFile($"PPT增强预览跳转失败:{item.SlideNumber}", LogHelper.LogType.Warning); } @@ -2602,7 +2676,7 @@ namespace Ink_Canvas { slide = slides[i]; var imagePath = Path.Combine(tempDir, $"slide_{i:0000}.png"); - slide.Export(imagePath, "PNG", 320, 180); + slide.Export(imagePath, "PNG", 480, 270); var image = LoadBitmapImage(imagePath); if (image == null) continue;