66using Windows . UI . Xaml ;
77using Windows . UI . Xaml . Controls ;
88using Windows . UI . Xaml . Markup ;
9- using Windows . UI . Xaml . Media ;
109using Windows . UI . Xaml . Media . Animation ;
10+ using NavigationView = Microsoft . UI . Xaml . Controls . NavigationView ;
11+ using NavigationViewSelectionChangedEventArgs = Microsoft . UI . Xaml . Controls . NavigationViewSelectionChangedEventArgs ;
1112
1213namespace Microsoft . Toolkit . Uwp . UI . Controls
1314{
@@ -36,8 +37,10 @@ public class TabbedCommandBar : NavigationView
3637 public TabbedCommandBar ( )
3738 {
3839 DefaultStyleKey = typeof ( TabbedCommandBar ) ;
40+ DefaultStyleResourceUri = new System . Uri ( "ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Core/Themes/Generic.xaml" ) ;
3941
4042 SelectionChanged += SelectedItemChanged ;
43+ Loaded += TabbedCommandBar_Loaded ;
4144 }
4245
4346 /// <inheritdoc/>
@@ -55,6 +58,15 @@ protected override void OnApplyTemplate()
5558 _tabbedCommandBarContentBorder = GetTemplateChild ( "PART_TabbedCommandBarContentBorder" ) as Border ;
5659 _tabChangedStoryboard = GetTemplateChild ( "TabChangedStoryboard" ) as Storyboard ;
5760
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.
5870 SelectedItem = MenuItems . FirstOrDefault ( ) ;
5971 }
6072
0 commit comments