Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ContextMenuManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
AlwaysShowHeader="False"
IsBackButtonVisible="Collapsed"
IsSettingsVisible="False"
OpenPaneLength="185"
SelectionChanged="NavView_SelectionChanged">

<!-- Main content area -->
Expand Down
46 changes: 46 additions & 0 deletions ContextMenuManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using DrawingSize = System.Drawing.Size;

namespace ContextMenuManager
Expand Down Expand Up @@ -63,6 +64,7 @@ public MainWindow()

// Populate navigation items from AppString
BuildNavigation();
AdjustPaneWidthToContent();

// First-run language download prompt
Loaded += (_, _) => FirstRunDownloadLanguage();
Expand Down Expand Up @@ -149,6 +151,50 @@ private void BuildNavigation()
}
}

// Sizes OpenPaneLength to fit the widest item label so translations don't get clipped.
// Chrome values are measured against iNKORE.UI.WPF.Modern v0.10.2's NavigationViewItem template
// (Segoe UI 14pt): an item's rendered width = LPad + content + RPad, where LPad/RPad depend
// on whether the item has an icon or an expand chevron.
private void AdjustPaneWidthToContent()
{
const double chevronChrome = 100; // expandable parent (icon + chevron slot)
const double iconChrome = 74; // leaf with icon (footer items)
const double plainChrome = 67; // nested leaf, no icon
const double minPaneLength = 185;
const double maxPaneLength = 400;

var typeface = new Typeface(NavView.FontFamily, NavView.FontStyle, NavView.FontWeight, NavView.FontStretch);
var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;
var fontSize = NavView.FontSize > 0 ? NavView.FontSize : 14;

double maxRequired = 0;
foreach (var item in EnumerateNavigationItems())
{
if (item.Content is not string text || text.Length == 0) continue;

double chrome = item.MenuItems.Count > 0 ? chevronChrome
: item.Icon != null ? iconChrome
: plainChrome;

var ft = new FormattedText(
text,
CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight,
typeface,
fontSize,
Brushes.Black,
pixelsPerDip);

double required = ft.Width + chrome;
if (required > maxRequired) maxRequired = required;
}

NavView.OpenPaneLength = Math.Clamp(
Math.Ceiling(maxRequired),
minPaneLength,
maxPaneLength);
}

private static NavigationViewItem MakeSectionItem(string content, string glyph)
{
var item = new NavigationViewItem() { Content = content, Icon = new FontIcon { Glyph = glyph } };
Expand Down
Loading