6
6
using Windows . UI . Xaml ;
7
7
using Windows . UI . Xaml . Controls ;
8
8
using Windows . UI . Xaml . Markup ;
9
- using Windows . UI . Xaml . Media ;
10
9
using Windows . UI . Xaml . Media . Animation ;
10
+ using NavigationView = Microsoft . UI . Xaml . Controls . NavigationView ;
11
+ using NavigationViewSelectionChangedEventArgs = Microsoft . UI . Xaml . Controls . NavigationViewSelectionChangedEventArgs ;
11
12
12
13
namespace Microsoft . Toolkit . Uwp . UI . Controls
13
14
{
@@ -36,8 +37,10 @@ public class TabbedCommandBar : NavigationView
36
37
public TabbedCommandBar ( )
37
38
{
38
39
DefaultStyleKey = typeof ( TabbedCommandBar ) ;
40
+ DefaultStyleResourceUri = new System . Uri ( "ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Core/Themes/Generic.xaml" ) ;
39
41
40
42
SelectionChanged += SelectedItemChanged ;
43
+ Loaded += TabbedCommandBar_Loaded ;
41
44
}
42
45
43
46
/// <inheritdoc/>
@@ -55,6 +58,15 @@ protected override void OnApplyTemplate()
55
58
_tabbedCommandBarContentBorder = GetTemplateChild ( "PART_TabbedCommandBarContentBorder" ) as Border ;
56
59
_tabChangedStoryboard = GetTemplateChild ( "TabChangedStoryboard" ) as Storyboard ;
57
60
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.
58
70
SelectedItem = MenuItems . FirstOrDefault ( ) ;
59
71
}
60
72
0 commit comments