2025-10-13 13:21:29 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Windows;
|
2025-10-13 11:13:42 +08:00
|
|
|
|
using System.Windows.Controls;
|
2025-10-13 13:21:29 +08:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2025-10-13 11:13:42 +08:00
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
|
|
2025-10-13 13:21:29 +08:00
|
|
|
|
namespace WpfApp.Utils
|
2025-10-13 11:13:42 +08:00
|
|
|
|
{
|
2025-10-13 13:21:29 +08:00
|
|
|
|
public static class WindowHelper
|
2025-10-13 11:13:42 +08:00
|
|
|
|
{
|
2025-10-13 13:21:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 通用窗口打开方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="page">要显示的页面实例</param>
|
|
|
|
|
|
/// <param name="title">窗口标题</param>
|
|
|
|
|
|
/// <param name="width">窗口宽度</param>
|
|
|
|
|
|
/// <param name="height">窗口高度</param>
|
|
|
|
|
|
/// <param name="isResizable">是否允许调整大小</param>
|
|
|
|
|
|
/// <param name="iconPath">可选图标路径,如果为空使用默认图标</param>
|
|
|
|
|
|
public static void ShowPageDialog(Page page, string title, double width = 900, double height = 600, bool isResizable = false, string iconPath = null)
|
2025-10-13 11:13:42 +08:00
|
|
|
|
{
|
2025-10-13 13:21:29 +08:00
|
|
|
|
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
|
|
|
|
|
|
};
|
2025-10-13 13:38:02 +08:00
|
|
|
|
string defaultIconPath = iconPath == null ? IconHelper.GetIconPath("FMSDGAUGE-main.ico") : iconPath;
|
2025-10-13 13:21:29 +08:00
|
|
|
|
|
2025-10-13 13:38:02 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
navWin.Icon = new BitmapImage(new Uri(System.IO.Path.GetFullPath(defaultIconPath), UriKind.Absolute));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine($"设置图标失败: {ex.Message}");
|
|
|
|
|
|
}
|
2025-10-13 13:21:29 +08:00
|
|
|
|
|
2025-10-13 11:13:42 +08:00
|
|
|
|
|
2025-10-13 13:21:29 +08:00
|
|
|
|
navWin.ShowDialog();
|
|
|
|
|
|
}
|
2025-10-13 11:13:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|