Files
community/Ink Canvas/Windows/SettingsViews/Pages/BasicPage.xaml.cs
T

126 lines
4.7 KiB
C#
Raw Normal View History

using iNKORE.UI.WPF.Modern.Common.IconKeys;
2026-04-24 07:13:27 +08:00
using iNKORE.UI.WPF.Modern.Controls;
using System.Collections.ObjectModel;
using System.Reflection;
2026-03-29 17:39:52 +08:00
using System.Windows;
using System.Windows.Media;
2026-04-24 07:13:27 +08:00
using SWC = System.Windows.Controls;
2026-03-29 17:39:52 +08:00
2026-04-05 21:50:53 +08:00
namespace Ink_Canvas.Windows.SettingsViews.Pages
2026-03-29 17:39:52 +08:00
{
2026-04-24 07:13:27 +08:00
public class SubPageNavItem
2026-03-29 17:39:52 +08:00
{
2026-04-24 07:13:27 +08:00
public string Header { get; set; }
public string Description { get; set; }
public string PageTag { get; set; }
public string IconGlyph { get; set; }
public FontFamily IconFontFamily { get; set; }
2026-04-24 07:13:27 +08:00
}
public partial class BasicPage : SWC.Page
{
private readonly ObservableCollection<SubPageNavItem> _subPageItems = new();
2026-04-04 18:45:59 +08:00
public BasicPage()
2026-03-29 17:39:52 +08:00
{
InitializeComponent();
2026-04-24 07:13:27 +08:00
SubPageItems.ItemsSource = _subPageItems;
Loaded += BasicPage_Loaded;
}
private void BasicPage_Loaded(object sender, RoutedEventArgs e)
{
LoadSubPages();
}
private void LoadSubPages()
{
_subPageItems.Clear();
var settingsWindow = Window.GetWindow(this) as SettingsWindow;
if (settingsWindow == null) return;
var navView = settingsWindow.GetNavigationView();
if (navView == null) return;
foreach (var item in navView.MenuItems)
{
if (item is NavigationViewItem navItem)
{
string tag = navItem.Tag as string;
if (tag == "BasicPage" && navItem.MenuItems.Count > 0)
{
foreach (var child in navItem.MenuItems)
{
if (child is NavigationViewItem childItem)
{
string childTag = childItem.Tag as string;
if (!string.IsNullOrEmpty(childTag))
{
(string glyph, FontFamily fontFamily) = ExtractIconInfo(childItem);
2026-04-24 07:13:27 +08:00
string description = SWC.ToolTipService.GetToolTip(childItem) as string
?? $"点击跳转到{childItem.Content}";
_subPageItems.Add(new SubPageNavItem
{
Header = childItem.Content?.ToString() ?? "",
Description = description,
PageTag = childTag,
IconGlyph = glyph,
IconFontFamily = fontFamily
2026-04-24 07:13:27 +08:00
});
}
}
}
break;
}
}
}
}
private (string glyph, FontFamily fontFamily) ExtractIconInfo(NavigationViewItem navItem)
2026-04-24 07:13:27 +08:00
{
if (navItem.Icon is FontIcon fontIcon)
{
string glyph = fontIcon.Glyph ?? "\uE713";
FontFamily fontFamily = fontIcon.FontFamily ?? new FontFamily("Segoe Fluent Icons");
if (fontIcon.Icon != null)
{
string iconStr = fontIcon.Icon.ToString();
if (iconStr.Contains("_20_"))
{
string key24 = iconStr.Replace("_20_", "_24_");
var field = typeof(FluentSystemIcons).GetField(key24, BindingFlags.Public | BindingFlags.Static);
if (field != null)
{
var value = field.GetValue(null);
if (value is FontIconData data24)
{
glyph = data24.Glyph ?? glyph;
fontFamily = data24.FontFamily ?? fontFamily;
}
}
}
}
return (glyph, fontFamily);
}
2026-04-24 07:13:27 +08:00
if (navItem.Icon is SymbolIcon symbolIcon)
return (char.ConvertFromUtf32((int)symbolIcon.Symbol), new FontFamily("Segoe Fluent Icons"));
2026-04-24 07:13:27 +08:00
return ("\uE713", new FontFamily("Segoe Fluent Icons"));
2026-03-29 17:39:52 +08:00
}
2026-04-24 07:13:27 +08:00
private void SubPageCard_Click(object sender, RoutedEventArgs e)
2026-03-29 17:39:52 +08:00
{
2026-04-24 07:13:27 +08:00
if (sender is FrameworkElement element && element.Tag is string pageTag)
2026-03-29 17:39:52 +08:00
{
2026-04-24 07:13:27 +08:00
var settingsWindow = Window.GetWindow(this) as SettingsWindow;
settingsWindow?.NavigateToPage(pageTag);
2026-03-29 17:39:52 +08:00
}
}
}
}