Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated TabbedCommandBar for WinUI 2.6 #4132

Merged
11 commits merged into from
Jul 30, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<RowDefinition/>
</Grid.RowDefinitions>

<controls:TabbedCommandBar>
<controls:TabbedCommandBar> <!-- IsBackButtonVisible="Visible" -->
<controls:TabbedCommandBar.AutoSuggestBox>
<AutoSuggestBox QueryIcon="Find" AutomationProperties.Name="Search" />
</controls:TabbedCommandBar.AutoSuggestBox>
<controls:TabbedCommandBar.PaneFooter>
<CommandBar Background="Transparent" DefaultLabelPosition="Right">
<AppBarButton Label="Share" Icon="Share"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView;
using NavigationViewSelectionChangedEventArgs = Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
Expand Down Expand Up @@ -36,8 +37,10 @@ public class TabbedCommandBar : NavigationView
public TabbedCommandBar()
{
DefaultStyleKey = typeof(TabbedCommandBar);
DefaultStyleResourceUri = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Core/Themes/Generic.xaml");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to remove the need for this line of code, but was unsuccessful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we had this same issue with ColorPicker as well. We have an issue on WinUI for this here: microsoft/microsoft-ui-xaml#3502 - I suppose we could link to it, but I think we need it on all controls for WinUI 3, right @azchohfi?


SelectionChanged += SelectedItemChanged;
Loaded += TabbedCommandBar_Loaded;
}

/// <inheritdoc/>
Expand All @@ -55,6 +58,15 @@ protected override void OnApplyTemplate()
_tabbedCommandBarContentBorder = GetTemplateChild("PART_TabbedCommandBarContentBorder") as Border;
_tabChangedStoryboard = GetTemplateChild("TabChangedStoryboard") as Storyboard;

// TODO: We could maybe optimize and use a lower-level Loaded event for what's hosting the MenuItems
// to set SelectedItem, but then we may have to pull in another template part, so think we're OK
// to do the Loaded event at the top level.
}

private void TabbedCommandBar_Loaded(object sender, RoutedEventArgs e)
{
// We need to select the item after the template is realized, otherwise the SelectedItem's
// DataTemplate bindings don't properly navigate the visual tree.
SelectedItem = MenuItems.FirstOrDefault();
}

Expand Down
Loading