Skip to content

Commit c43aaee

Browse files
Move SelectedItem setting for TabbedCommandBar to mitigate binding timing issue
1 parent f86357a commit c43aaee

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Core/TabbedCommandBar/TabbedCommandBar.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public TabbedCommandBar()
4040
DefaultStyleResourceUri = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Core/Themes/Generic.xaml");
4141

4242
SelectionChanged += SelectedItemChanged;
43+
Loaded += TabbedCommandBar_Loaded;
4344
}
4445

4546
/// <inheritdoc/>
@@ -57,6 +58,15 @@ protected override void OnApplyTemplate()
5758
_tabbedCommandBarContentBorder = GetTemplateChild("PART_TabbedCommandBarContentBorder") as Border;
5859
_tabChangedStoryboard = GetTemplateChild("TabChangedStoryboard") as Storyboard;
5960

61+
// TODO: We could maybe optimize and use a lower-level Loaded event for what's hosting the MenuItems
62+
// to set SelectedItem, but then we may have to pull in another template part, so think we're OK
63+
// to do the Loaded event at the top level.
64+
}
65+
66+
private void TabbedCommandBar_Loaded(object sender, RoutedEventArgs e)
67+
{
68+
// We need to select the item after the template is realized, otherwise the SelectedItem's
69+
// DataTemplate bindings don't properly navigate the visual tree.
6070
SelectedItem = MenuItems.FirstOrDefault();
6171
}
6272

0 commit comments

Comments
 (0)