Skip to content

Commit 1bd6f70

Browse files
hifihedgehogclaude
andcommitted
Fix Add Controller popup breaking after About/Settings, remove blue animation
- SelectsOnInvoked=false on AddController so it never gets selected - Handle AddController via ItemInvoked instead of SelectionChanged - Fix SelectNavItemByTag to search FooterMenuItems and handle Settings Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a1aa51f commit 1bd6f70

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

PadForge.App/MainWindow.xaml.cs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,9 @@ private void BuildNavigationItems()
837837
NavView.PreviewMouseLeftButtonUp += OnNavViewDragEnd;
838838
NavView.PreviewKeyDown += OnNavViewDragKeyDown;
839839

840+
// ItemInvoked fires even when SelectsOnInvoked=false (used for AddController).
841+
NavView.ItemInvoked += NavView_ItemInvoked;
842+
840843
NavView.MenuItems.Clear();
841844

842845
// Dashboard.
@@ -963,7 +966,8 @@ or nameof(NavControllerItemViewModel.IsInitializing))
963966
{
964967
Tag = "AddController",
965968
Icon = new FontIcon { Glyph = "\uE710" }, // + icon
966-
Content = "Add Controller"
969+
Content = "Add Controller",
970+
SelectsOnInvoked = false
967971
};
968972
NavView.MenuItems.Add(addItem);
969973
}
@@ -2175,6 +2179,12 @@ private int FindLastSlotOfType(VirtualControllerType type)
21752179
/// </summary>
21762180
private void SelectNavItemByTag(string tag)
21772181
{
2182+
if (tag == "Settings")
2183+
{
2184+
NavView.SelectedItem = NavView.SettingsItem;
2185+
return;
2186+
}
2187+
21782188
foreach (var mi in NavView.MenuItems)
21792189
{
21802190
if (mi is NavigationViewItem nvi && nvi.Tag?.ToString() == tag)
@@ -2183,6 +2193,30 @@ private void SelectNavItemByTag(string tag)
21832193
return;
21842194
}
21852195
}
2196+
2197+
foreach (var mi in NavView.FooterMenuItems)
2198+
{
2199+
if (mi is NavigationViewItem nvi && nvi.Tag?.ToString() == tag)
2200+
{
2201+
NavView.SelectedItem = nvi;
2202+
return;
2203+
}
2204+
}
2205+
}
2206+
2207+
/// <summary>
2208+
/// Handles clicks on non-selectable NavigationView items (e.g. "Add Controller").
2209+
/// SelectsOnInvoked=false prevents the blue indicator from moving to these items,
2210+
/// but ItemInvoked still fires so we can show the popup.
2211+
/// </summary>
2212+
private void NavView_ItemInvoked(NavigationView sender,
2213+
NavigationViewItemInvokedEventArgs args)
2214+
{
2215+
if (args.InvokedItemContainer is NavigationViewItem nvi
2216+
&& nvi.Tag?.ToString() == "AddController")
2217+
{
2218+
ShowControllerTypePopup(nvi);
2219+
}
21862220
}
21872221

21882222
private void NavView_SelectionChanged(NavigationView sender,
@@ -2209,37 +2243,6 @@ private void NavView_SelectionChanged(NavigationView sender,
22092243
return;
22102244
}
22112245

2212-
// "Add Controller" shows a type-selection popup, then creates a slot.
2213-
// Deferred to next dispatcher frame because CreateSlot() triggers
2214-
// RebuildControllerSection() which modifies NavView.MenuItems —
2215-
// doing that synchronously inside SelectionChanged crashes ModernWpf's
2216-
// internal ItemsRepeater layout.
2217-
if (tag == "AddController")
2218-
{
2219-
// Immediately reselect the previous page so the blue selection
2220-
// indicator never visually lands on the "Add Controller" item.
2221-
SelectNavItemByTag(_viewModel.SelectedNavTag ?? "Dashboard");
2222-
2223-
// Defer the popup + CreateSlot because they trigger
2224-
// RebuildControllerSection() which modifies NavView.MenuItems —
2225-
// doing that synchronously inside SelectionChanged crashes ModernWpf's
2226-
// internal ItemsRepeater layout.
2227-
Dispatcher.BeginInvoke(new Action(() =>
2228-
{
2229-
NavigationViewItem addItem = null;
2230-
foreach (var mi in NavView.MenuItems)
2231-
{
2232-
if (mi is NavigationViewItem nvi && nvi.Tag?.ToString() == "AddController")
2233-
{
2234-
addItem = nvi;
2235-
break;
2236-
}
2237-
}
2238-
ShowControllerTypePopup(addItem);
2239-
}));
2240-
return;
2241-
}
2242-
22432246
// Update ViewModel navigation state.
22442247
_viewModel.SelectedNavTag = tag;
22452248

0 commit comments

Comments
 (0)