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

97 lines
3.3 KiB
C#
Raw Normal View History

2026-04-24 07:13:27 +08:00
using iNKORE.UI.WPF.Modern.Controls;
using System.Collections.ObjectModel;
2026-03-29 17:39:52 +08:00
using System.Windows;
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 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 = ExtractIconGlyph(childItem);
string description = SWC.ToolTipService.GetToolTip(childItem) as string
?? $"点击跳转到{childItem.Content}";
_subPageItems.Add(new SubPageNavItem
{
Header = childItem.Content?.ToString() ?? "",
Description = description,
PageTag = childTag,
IconGlyph = glyph
});
}
}
}
break;
}
}
}
}
private string ExtractIconGlyph(NavigationViewItem navItem)
{
if (navItem.Icon is FontIcon fontIcon)
return fontIcon.Glyph ?? "\uE713";
if (navItem.Icon is SymbolIcon symbolIcon)
return char.ConvertFromUtf32((int)symbolIcon.Symbol);
return "\uE713";
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
}
}
}
}