Skip to content
Closed
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
34 changes: 17 additions & 17 deletions Microsoft.Toolkit.Uwp.SampleApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
RequiresPointerMode="Auto">

<Application.Resources>
<ResourceDictionary>
<!-- Color Resources -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Styles/Themes.xaml" />
<ResourceDictionary Source="ms-appx:///Styles/Generic.xaml" />
<Application.Resources>
<ResourceDictionary>
<!-- Color Resources -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Styles/Themes.xaml" />
<ResourceDictionary Source="ms-appx:///Styles/Generic.xaml" />

<!-- WinUI -->
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</ResourceDictionary.MergedDictionaries>
<!-- WinUI -->
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>

<!-- Converters -->
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
<!-- Converters -->
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />

<converters:EmptyStringToObjectConverter x:Key="EmptyStringToObject"
EmptyValue="Collapsed"
NotEmptyValue="Visible" />
<converters:EmptyStringToObjectConverter x:Key="EmptyStringToObject"
EmptyValue="Collapsed"
NotEmptyValue="Visible" />

<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</ResourceDictionary>
</Application.Resources>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
<Content Include="Icons\More.png" />
<Content Include="Icons\Notifications.png" />
<Content Include="Icons\Services.png" />
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.png" />
<Content Include="SamplePages\TilesBrush\TilesBrush.png" />
<Content Include="SamplePages\Eyedropper\Eyedropper.png" />
<Content Include="SamplePages\OnDevice\OnDevice.png" />
Expand Down Expand Up @@ -515,6 +516,9 @@
<Compile Include="SamplePages\FocusBehavior\FocusBehaviorPage.xaml.cs">
<DependentUpon>FocusBehaviorPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\TabbedCommandBar\TabbedCommandBarPage.xaml.cs">
<DependentUpon>TabbedCommandBarPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\TilesBrush\TilesBrushPage.xaml.cs">
<DependentUpon>TilesBrushPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -1001,6 +1005,14 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.bind">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Content>
<Page Include="SamplePages\TabbedCommandBar\TabbedCommandBarPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\TilesBrush\TilesBrushPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d">
<Grid>
<controls:TabbedCommandBar>
<controls:TabbedCommandBar.Footer>
<CommandBar Background="Transparent" DefaultLabelPosition="Right">
<AppBarButton Label="Share" Icon="Share"/>
<AppBarButton Label="Comments" Icon="Message"/>
</CommandBar>
</controls:TabbedCommandBar.Footer>
<controls:TabbedCommandBar.Resources>
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="SystemControlChromeMediumLowAcrylicWindowMediumBrush" />
<StaticResource x:Key="TabbedCommandBarContentBackground" ResourceKey="SystemControlChromeLowAcrylicWindowBrush" />
</controls:TabbedCommandBar.Resources>
Comment on lines +15 to +18
Copy link
Member

Choose a reason for hiding this comment

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

I didn't notice a big difference without these resources? We should just have the example be as default as possible.

<controls:TabbedCommandBarItem Header="Home">
<AppBarButton Icon="Undo" Label="Undo"/>
<AppBarButton Icon="Redo" Label="Redo"/>
<AppBarButton Icon="Paste" Label="Paste"/>
<AppBarSeparator />
<AppBarElementContainer>
<ComboBox SelectedIndex="0">
<ComboBoxItem Content="Arial" />
<ComboBoxItem Content="Calibri" />
<ComboBoxItem Content="JetBrains Mono" />
<ComboBoxItem Content="Roboto" />
<ComboBoxItem Content="Sergio UI" />
<ComboBoxItem Content="Sergio UI Semibold" />
</ComboBox>
</AppBarElementContainer>
<AppBarToggleButton Icon="Bold" Label="Bold" />
<AppBarToggleButton Icon="Italic" Label="Italic" />
<AppBarToggleButton Icon="Underline" Label="Underline" />
</controls:TabbedCommandBarItem>
<controls:TabbedCommandBarItem Header="Insert">
<AppBarButton Icon="Pictures" Label="Pictures">
<AppBarButton.Flyout>
<MenuFlyout Placement="BottomEdgeAlignedLeft">
<MenuFlyoutItem Text="This Device">
<MenuFlyoutItem.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xEC4E;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Stock Images">
<MenuFlyoutItem.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE721;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem Icon="Globe" Text="Online Pictures" />
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
<AppBarButton Label="Shapes">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe UI Symbol" Glyph="&#x25A1;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="Icons">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xED58;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="3D Models">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xF158;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarSeparator/>
<AppBarButton Label="Add-ins">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xECAA;" />
</AppBarButton.Icon>
</AppBarButton>
<controls:TabbedCommandBarItem.SecondaryCommands>
<AppBarButton Icon="Add" Label="New item" />
</controls:TabbedCommandBarItem.SecondaryCommands>
</controls:TabbedCommandBarItem>
</controls:TabbedCommandBar>
</Grid>
</Page>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.TabbedCommandBarPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<!-- Shallow Copy -->
<Grid Visibility="Collapsed">
<controls:TabbedCommandBar>
<controls:TabbedCommandBarItem />
</controls:TabbedCommandBar>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class TabbedCommandBarPage : Page
{
public TabbedCommandBarPage()
{
this.InitializeComponent();
}
}
}
10 changes: 10 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@
"XamlCodeFile": "TokenizingTextBoxXaml.bind",
"Icon": "/SamplePages/TokenizingTextBox/TokenizingTextBox.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/TokenizingTextBox.md"
},
{
"Name": "TabbedCommandBar",
"Type": "TabbedCommandBarPage",
"Subcategory": "Layout",
"About": "A control for displaying multiple CommandBars in the same space, like Microsoft Office's ribbon.",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/TabbedCommandBar",
"XamlCodeFile": "TabbedCommandBar.bind",
"Icon": "/SamplePages/TabbedCommandBar/TabbedCommandBar.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/TabbedCommandBar.md"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<Compile Include="RangeSelectorMetadata.cs" />
<Compile Include="RotatorTileMetadata.cs" />
<Compile Include="ScrollHeaderMetadata.cs" />
<Compile Include="TabbedCommandBarMetadata.cs" />
<Compile Include="TextToolbarMetadata.cs" />
<Compile Include="TileControlMetadata.cs" />
<Compile Include="WrapPanelMetadata.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Windows.Design.Metadata;
using Microsoft.Windows.Design.PropertyEditing;
using System.ComponentModel;

namespace Microsoft.Toolkit.Uwp.UI.Controls.Design
Copy link
Member

Choose a reason for hiding this comment

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

We're moving to the new format in #3318. I don't think there's a way for you to pre-emptively move there though until that's merged.

@Nirmal4G correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

{
internal class TabbedCommandBarMetadata : AttributeTableBuilder
{
public TabbedCommandBarMetadata()
: base()
{
AddCallback(typeof(TabbedCommandBar),
b =>
{
b.AddCustomAttributes(nameof(TabbedCommandBar.Items),
new PropertyOrderAttribute(PropertyOrder.Early),
new CategoryAttribute(Properties.Resources.CategoryCommon),
//The following is necessary because this is a collection of an abstract type, so we help
//the designer with populating supported types that can be added to the collection
new NewItemTypesAttribute(new System.Type[] {
typeof(TabbedCommandBarItem),
}),
new AlternateContentPropertyAttribute()
);
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<Page Update="RemoteDevicePicker\RemoteDevicePicker.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Ribbon\Ribbon.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Comment on lines +74 to +76
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<Page Update="Ribbon\Ribbon.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>

This looks extra?

<Page Update="TokenizingTextBox\TokenizingTextBox.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
117 changes: 117 additions & 0 deletions Microsoft.Toolkit.Uwp.UI.Controls/TabbedCommandBar/TabbedCommandBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media.Animation;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// A basic ribbon control that houses <see cref="TabbedCommandBarItem"/>s
/// </summary>
[ContentProperty(Name = nameof(Items))]
[TemplatePart(Name = "PART_RibbonNavigationView", Type = typeof(NavigationView))]
[TemplatePart(Name = "PART_RibbonContent", Type = typeof(ContentControl))]
[TemplatePart(Name = "PART_TabChangedStoryboard", Type = typeof(Storyboard))]
public class TabbedCommandBar : Control
{
private NavigationView _ribbonNavigationView = null;
private ContentControl _ribbonContent = null;
private Storyboard _tabChangedStoryboard = null;

// This should probably be made public at some point
private TabbedCommandBarItem SelectedTab { get; set; }

/// <summary>
/// Identifies the <see cref="Items"/> property.
/// </summary>
public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register(
nameof(Items),
typeof(IList<object>),
typeof(TabbedCommandBar),
new PropertyMetadata(new List<object>()));

/// <summary>
/// Identifies the <see cref="Footer"/> property.
/// </summary>
public static readonly DependencyProperty FooterProperty = DependencyProperty.Register(
nameof(Footer),
typeof(UIElement),
typeof(TabbedCommandBar),
new PropertyMetadata(new Border()));

// I would prefer this be an IList<TabbedCommandBarItem>, but Intellisense really doesn't like that.
/// <summary>
/// Gets or sets A list of <see cref="TabbedCommandBarItem"/>s to display in this <see cref="TabbedCommandBar"/>.
/// </summary>
public IList<object> Items
{
get { return (IList<object>)GetValue(ItemsProperty); }
set { SetValue(ItemsProperty, value); }
}

/// <summary>
/// Gets or sets the <see cref="UIElement"/> to be displayed in the footer of the ribbon tab strip.
/// </summary>
public UIElement Footer
{
get { return (UIElement)GetValue(FooterProperty); }
set { SetValue(FooterProperty, value); }
}

/// <summary>
/// Initializes a new instance of the <see cref="TabbedCommandBar"/> class.
/// </summary>
public TabbedCommandBar()
{
DefaultStyleKey = typeof(TabbedCommandBar);
}

/// <inheritdoc/>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

// Get RibbonContent first, since setting SelectedItem requires it
_ribbonContent = GetTemplateChild("PART_RibbonContent") as ContentControl;

_ribbonNavigationView = GetTemplateChild("PART_RibbonNavigationView") as NavigationView;
if (_ribbonNavigationView != null)
{
// Populate the NavigationView with items
// TODO: Get binding working, necessary for contextual tabs
_ribbonNavigationView.MenuItems.Clear();
foreach (TabbedCommandBarItem item in Items)
{
_ribbonNavigationView.MenuItems.Add(item);
}
_ribbonNavigationView.PaneFooter = Footer;

_ribbonNavigationView.SelectionChanged += RibbonNavigationView_SelectionChanged;
_ribbonNavigationView.SelectedItem = _ribbonNavigationView.MenuItems.FirstOrDefault();
}

_tabChangedStoryboard = GetTemplateChild(nameof(_tabChangedStoryboard)) as Storyboard;
}

private void RibbonNavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.SelectedItem is TabbedCommandBarItem item)
{
_ribbonContent.Content = item;
_tabChangedStoryboard?.Begin();
}
else if (args.SelectedItem is NavigationViewItem navItem)
{
// This code is a hack and is only temporary, because I can't get binding to work.
// RibbonContent might be null here, there should be a check
_ribbonContent.Content = Items[System.Math.Min(Items.Count - 1, _ribbonNavigationView.MenuItems.IndexOf(navItem))];
}
}
}
}
Loading