添加图标查询帮助类
This commit is contained in:
parent
f990cea469
commit
3a11035329
|
|
@ -85,32 +85,32 @@ public partial class MainWindow : Window
|
||||||
|
|
||||||
private void OnFilePageButtonClick(object sender, RoutedEventArgs e)
|
private void OnFilePageButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowHelper.ShowPageDialog(new FilePage(), "记录列表", 810, 600,isResizable: false, "..\\..\\..\\src\\public\\Icons\\programIcons\\main1-File.ico");
|
WindowHelper.ShowPageDialog(new FilePage(), "记录列表", 810, 600,isResizable: false, IconHelper.GetIconPath("main1-File.ico"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnConfigPageButtonClick(object sender, RoutedEventArgs e)
|
private void OnConfigPageButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowHelper.ShowPageDialog(new ConfigPage(), "配置", 972, 648, isResizable: false, "..\\..\\..\\src\\public\\Icons\\programIcons\\main2-Config.ico");
|
WindowHelper.ShowPageDialog(new ConfigPage(), "配置", 972, 648, isResizable: false, IconHelper.GetIconPath("main2-Config.ico"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStandardPageButtonClick(object sender, RoutedEventArgs e)
|
private void OnStandardPageButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowHelper.ShowPageDialog(new StandardPage(), "主标定", 972, 648, isResizable: true, "..\\..\\..\\src\\public\\Icons\\programIcons\\main3-Standard.ico");
|
WindowHelper.ShowPageDialog(new StandardPage(), "主标定", 972, 648, isResizable: true, IconHelper.GetIconPath("main3-Standard.ico"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGaugePageButtonClick(object sender, RoutedEventArgs e)
|
private void OnGaugePageButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowHelper.ShowPageDialog(new GaugePage(), "Gauge R&&R", 1080, 720, isResizable:false, "..\\..\\..\\src\\public\\Icons\\programIcons\\main4-Gauge.ico");
|
WindowHelper.ShowPageDialog(new GaugePage(), "Gauge R&&R", 1080, 720, isResizable:false, IconHelper.GetIconPath("main4-Gauge.ico"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCgCgkPageButtonClick(object sender, RoutedEventArgs e)
|
private void OnCgCgkPageButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowHelper.ShowPageDialog(new CgCgkPage(), "CgCgk", 972, 648, isResizable: true, "..\\..\\..\\src\\public\\Icons\\programIcons\\main5-CgCgk.ico");
|
WindowHelper.ShowPageDialog(new CgCgkPage(), "CgCgk", 972, 648, isResizable: true, IconHelper.GetIconPath("main5-CgCgk.ico"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSysSetPageButtonClick(object sender, RoutedEventArgs e)
|
private void OnSysSetPageButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowHelper.ShowPageDialog(new SysSetPage(), "系统设置", 810, 600, isResizable:false, "..\\..\\..\\src\\public\\Icons\\programIcons\\main6-SysSet.ico");
|
WindowHelper.ShowPageDialog(new SysSetPage(), "系统设置", 810, 600, isResizable:false, IconHelper.GetIconPath("main6-SysSet.ico"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
58
Utils/IconHelper.cs
Normal file
58
Utils/IconHelper.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace WpfApp.Utils
|
||||||
|
{
|
||||||
|
public static class IconHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取图标路径(智能搜索)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="iconFileName">图标文件名,例如 "FMSDGAUGE-main.ico",为空使用默认图标</param>
|
||||||
|
/// <param name="externalDirs">可选外部搜索目录</param>
|
||||||
|
/// <returns>图标绝对路径</returns>
|
||||||
|
public static string GetIconPath(string iconFileName = null, string[] externalDirs = null)
|
||||||
|
{
|
||||||
|
// 默认图标文件名
|
||||||
|
string defaultIconName = "FMSDGAUGE-main.ico";
|
||||||
|
iconFileName ??= defaultIconName;
|
||||||
|
|
||||||
|
// 默认项目图标目录(相对于 EXE)
|
||||||
|
string projectIconDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\src\public\Icons");
|
||||||
|
|
||||||
|
// 先搜索项目目录
|
||||||
|
string path = SearchDirectory(projectIconDir, iconFileName);
|
||||||
|
if (!string.IsNullOrEmpty(path))
|
||||||
|
return path;
|
||||||
|
|
||||||
|
// 再搜索外部目录
|
||||||
|
if (externalDirs != null)
|
||||||
|
{
|
||||||
|
foreach (var dir in externalDirs)
|
||||||
|
{
|
||||||
|
path = SearchDirectory(dir, iconFileName);
|
||||||
|
if (!string.IsNullOrEmpty(path))
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 都没找到就抛异常
|
||||||
|
throw new FileNotFoundException($"找不到图标文件: {iconFileName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 在指定目录及子目录搜索文件
|
||||||
|
/// </summary>
|
||||||
|
private static string SearchDirectory(string rootDir, string fileName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var files = Directory.GetFiles(rootDir, fileName, SearchOption.AllDirectories);
|
||||||
|
if (files.Length > 0)
|
||||||
|
return Path.GetFullPath(files[0]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -31,11 +31,7 @@ namespace WpfApp.Utils
|
||||||
Owner = Application.Current.MainWindow,
|
Owner = Application.Current.MainWindow,
|
||||||
ResizeMode = isResizable ? ResizeMode.CanResize : ResizeMode.NoResize
|
ResizeMode = isResizable ? ResizeMode.CanResize : ResizeMode.NoResize
|
||||||
};
|
};
|
||||||
string defaultIconPath = null;
|
string defaultIconPath = iconPath == null ? IconHelper.GetIconPath("FMSDGAUGE-main.ico") : iconPath;
|
||||||
if (iconPath == null)
|
|
||||||
defaultIconPath = @"..\..\..\src\public\Icons\programIcons\FMSDGAUGE-main.ico";
|
|
||||||
else
|
|
||||||
defaultIconPath = iconPath;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user