using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using System.Windows.Navigation; namespace WpfApp.Utils { public static class WindowHelper { /// /// 通用窗口打开方法 /// /// 要显示的页面实例 /// 窗口标题 /// 窗口宽度 /// 窗口高度 /// 是否允许调整大小 /// 可选图标路径,如果为空使用默认图标 public static void ShowPageDialog(Page page, string title, double width = 900, double height = 600, bool isResizable = false, string iconPath = null) { var navWin = new NavigationWindow { Content = page, Title = title, Width = width, Height = height, ShowsNavigationUI = false, WindowStartupLocation = WindowStartupLocation.CenterOwner, WindowStyle = WindowStyle.ToolWindow, Owner = Application.Current.MainWindow, ResizeMode = isResizable ? ResizeMode.CanResize : ResizeMode.NoResize }; string defaultIconPath = null; if (iconPath == null) defaultIconPath = @"..\..\..\src\public\Icons\programIcons\FMSDGAUGE-main.ico"; else defaultIconPath = iconPath; try { navWin.Icon = new BitmapImage(new Uri(System.IO.Path.GetFullPath(defaultIconPath), UriKind.Absolute)); } catch (Exception ex) { Console.WriteLine($"设置图标失败: {ex.Message}"); } navWin.ShowDialog(); } } }