-
Notifications
You must be signed in to change notification settings - Fork 79
[Experiment] TitleBar #459
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
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
0fcb076
Init
niels9001 f75784b
Remove files
niels9001 a39a294
Delete BlankPage1.xaml.cs
niels9001 f61434b
Improve samples
niels9001 7b82a95
XAML styling
niels9001 cb24ed5
UpdateCaptionButtons
ghost1372 b4529e4
Remove GetAppWindow() and Use Window.AppWindow
ghost1372 8094a33
Merge pull request #462 from ghost1372/TitleBar-AppWindow
niels9001 2015162
Merge branch 'niels9001/titlebar-experiment' into TitleBar-CaptionBut…
ghost1372 3e63cd7
Merge pull request #461 from ghost1372/TitleBar-CaptionButtons
niels9001 571f33c
Improve reset
niels9001 8f06ff3
Merge branch 'niels9001/titlebar-experiment' of https://github.com/Co…
niels9001 56fc9de
Address feedback
niels9001 6b9887c
Update TitleBar.md
niels9001 8c959e7
Fix CI
niels9001 4dfd4ae
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 4337e64
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 65f7e15
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 0972be5
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 8e84104
Fix PaneButton
ghost1372 b21d4c3
Merge pull request #506 from ghost1372/Fix-TitleBar
niels9001 6bec342
Fix Drag regions
ghost1372 f748819
Remove WindowNative and use AppWindow.Id
ghost1372 489cf3a
Merge pull request #507 from ghost1372/Fix-TitleBar2
niels9001 4a7d568
Update components/TitleBar/samples/TitleBar.md
niels9001 3b37fe5
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 e19de6e
Fix TitleBar Drag Region
ghost1372 c8ba80c
Use WASDK v1.4 new Custom TitleBar API and Simplify Calculating Rects
ghost1372 27f440a
Remove unused Codes
ghost1372 abe0fe3
Move GetRasterizationScaleForElement out of loop
ghost1372 c0e54a6
Add ContextMenu Support
ghost1372 3ef7c07
Update TitleBar.WASDK.cs
ghost1372 4c4f776
Merge pull request #508 from ghost1372/Fix-TitleBar3
niels9001 b71ccbb
Add Missing #if WINAPPSDK
ghost1372 91a032c
Merge pull request #513 from ghost1372/niels9001/titlebar-experiment
niels9001 c4d5b38
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 2cb787e
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 cb83879
Fixed nullability errors
Arlodotexe 4fb3530
Fixed invalid reference in XML comment
Arlodotexe 396c61a
Restrict TitleBar MultiTargets to uwp and wasdk
Arlodotexe aa780a5
Remove empty example test methods
Arlodotexe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @ECHO OFF | ||
|
|
||
| powershell ..\..\tooling\ProjectHeads\GenerateSingleSampleHeads.ps1 -componentPath %CD% %* |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <!-- | ||
| WinUI 2 under UWP uses TargetFramework uap10.0.* | ||
| WinUI 3 under WinAppSdk uses TargetFramework net6.0-windows10.* | ||
| However, under Uno-powered platforms, both WinUI 2 and 3 can share the same TargetFramework. | ||
|
|
||
| MSBuild doesn't play nicely with this out of the box, so we've made it easy for you. | ||
|
|
||
| For .NET Standard packages, you can use the Nuget Package Manager in Visual Studio. | ||
| For UWP / WinAppSDK / Uno packages, place the package references here. | ||
| --> | ||
| <Project> | ||
| <!-- WinUI 2 / UWP --> | ||
| <ItemGroup Condition="'$(IsUwp)' == 'true'"> | ||
| <!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> --> | ||
| </ItemGroup> | ||
|
|
||
| <!-- WinUI 2 / Uno --> | ||
| <ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'"> | ||
| <!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> --> | ||
| </ItemGroup> | ||
|
|
||
| <!-- WinUI 3 / WinAppSdk --> | ||
| <ItemGroup Condition="'$(IsWinAppSdk)' == 'true'"> | ||
| <!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> --> | ||
| </ItemGroup> | ||
|
|
||
| <!-- WinUI 3 / Uno --> | ||
| <ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'"> | ||
| <!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> --> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Page x:Class="TitleBarExperiment.Samples.FirstPage" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:controls="using:CommunityToolkit.WinUI.Controls" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:local="using:TitleBarExperiment.Samples" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <Grid> | ||
| <TextBlock HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| FontSize="48" | ||
| FontWeight="SemiBold" | ||
| Text="1" /> | ||
| </Grid> | ||
| </Page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // 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. | ||
|
|
||
| namespace TitleBarExperiment.Samples; | ||
| /// <summary> | ||
| /// An empty page that can be used on its own or navigated to within a Frame. | ||
| /// </summary> | ||
| public sealed partial class FirstPage : Page | ||
| { | ||
| public FirstPage() | ||
| { | ||
| this.InitializeComponent(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Page x:Class="TitleBarExperiment.Samples.SecondPage" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:controls="using:CommunityToolkit.WinUI.Controls" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:local="using:TitleBarExperiment.Samples" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <Grid> | ||
| <TextBlock HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| FontSize="48" | ||
| FontWeight="SemiBold" | ||
| Text="2" /> | ||
| </Grid> | ||
| </Page> |
15 changes: 15 additions & 0 deletions
15
components/TitleBar/samples/SamplePages/SecondPage.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // 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. | ||
|
|
||
| namespace TitleBarExperiment.Samples; | ||
| /// <summary> | ||
| /// An empty page that can be used on its own or navigated to within a Frame. | ||
| /// </summary> | ||
| public sealed partial class SecondPage : Page | ||
| { | ||
| public SecondPage() | ||
| { | ||
| this.InitializeComponent(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <Page x:Class="TitleBarExperiment.Samples.ShellPage" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:controls="using:CommunityToolkit.WinUI.Controls" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:local="using:TitleBarExperiment.Samples" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <Grid> | ||
| <Grid.RowDefinitions> | ||
| <RowDefinition Height="Auto" /> | ||
| <RowDefinition Height="*" /> | ||
| </Grid.RowDefinitions> | ||
|
|
||
| <controls:TitleBar x:Name="appTitleBar" | ||
| Title="Contoso" | ||
| AutoConfigureCustomTitleBar="True" | ||
| BackButtonClick="appTitleBar_BackButtonClick" | ||
| DisplayMode="Tall" | ||
| IsBackButtonVisible="True" | ||
| IsPaneButtonVisible="True" | ||
| PaneButtonClick="appTitleBar_PaneButtonClick" | ||
| Subtitle="Preview"> | ||
| <controls:TitleBar.Icon> | ||
| <BitmapIcon ShowAsMonochrome="False" | ||
| UriSource="ms-appx:///Assets/AppTitleBarIcon.png" /> | ||
| </controls:TitleBar.Icon> | ||
| <controls:TitleBar.Content> | ||
| <AutoSuggestBox PlaceholderText="Search.." /> | ||
| </controls:TitleBar.Content> | ||
| <controls:TitleBar.Footer> | ||
| <Button Width="32" | ||
| Height="32" | ||
| Padding="0" | ||
| BorderBrush="{ThemeResource CircleElevationBorderBrush}" | ||
| CornerRadius="16"> | ||
| <Button.Content> | ||
| <muxc:PersonPicture Width="32" | ||
| Height="32" | ||
| Initials="AB" | ||
| ProfilePicture="ms-appx:///Assets/Avatar.png" /> | ||
| </Button.Content> | ||
| <Button.Flyout> | ||
| <MenuFlyout Placement="Bottom"> | ||
| <MenuFlyoutItem Text="Manage account"> | ||
| <MenuFlyoutItem.Icon> | ||
| <FontIcon Glyph="" /> | ||
| </MenuFlyoutItem.Icon> | ||
| </MenuFlyoutItem> | ||
| <MenuFlyoutSeparator /> | ||
| <MenuFlyoutItem Text="Settings"> | ||
| <MenuFlyoutItem.Icon> | ||
| <FontIcon Glyph="" /> | ||
| </MenuFlyoutItem.Icon> | ||
| </MenuFlyoutItem> | ||
| </MenuFlyout> | ||
| </Button.Flyout> | ||
| </Button> | ||
| </controls:TitleBar.Footer> | ||
| </controls:TitleBar> | ||
| <muxc:NavigationView x:Name="NavView" | ||
| Grid.Row="1" | ||
| IsBackButtonVisible="Collapsed" | ||
| IsPaneToggleButtonVisible="False" | ||
| IsSettingsVisible="False" | ||
| Loaded="NavView_Loaded" | ||
| SelectionChanged="NavView_SelectionChanged"> | ||
| <muxc:NavigationView.MenuItems> | ||
| <muxc:NavigationViewItem Content="First item" | ||
| Tag="1"> | ||
| <muxc:NavigationViewItem.Icon> | ||
| <FontIcon Glyph="" /> | ||
| </muxc:NavigationViewItem.Icon> | ||
| </muxc:NavigationViewItem> | ||
| <muxc:NavigationViewItem Content="Second item" | ||
| Tag="2"> | ||
| <muxc:NavigationViewItem.Icon> | ||
| <FontIcon Glyph="" /> | ||
| </muxc:NavigationViewItem.Icon> | ||
| </muxc:NavigationViewItem> | ||
| </muxc:NavigationView.MenuItems> | ||
| <Frame x:Name="NavFrame" | ||
| Navigated="NavFrame_Navigated" /> | ||
| </muxc:NavigationView> | ||
| </Grid> | ||
| </Page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // 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. | ||
|
|
||
| namespace TitleBarExperiment.Samples; | ||
| /// <summary> | ||
| /// An empty page that can be used on its own or navigated to within a Frame. | ||
| /// </summary> | ||
| public sealed partial class ShellPage : Page | ||
| { | ||
| #if WINAPPSDK | ||
| public ShellPage(Window window) | ||
| { | ||
| this.InitializeComponent(); | ||
| appTitleBar.Window = window; | ||
| } | ||
| #else | ||
| public ShellPage() | ||
| { | ||
| this.InitializeComponent(); | ||
| Microsoft.UI.Xaml.Controls.BackdropMaterial.SetApplyToRootOrPageBackground(this, true); | ||
| } | ||
| #endif | ||
| private void appTitleBar_BackButtonClick(object sender, RoutedEventArgs e) | ||
| { | ||
| if (NavFrame.CanGoBack) | ||
| { | ||
| NavFrame.GoBack(); | ||
| } | ||
| } | ||
|
|
||
| private void appTitleBar_PaneButtonClick(object sender, RoutedEventArgs e) | ||
| { | ||
| NavView.IsPaneOpen = !NavView.IsPaneOpen; | ||
| } | ||
|
|
||
| private void NavView_SelectionChanged(MUXC.NavigationView sender, MUXC.NavigationViewSelectionChangedEventArgs args) | ||
| { | ||
| switch ((string)((MUXC.NavigationViewItem)NavView.SelectedItem).Tag) | ||
| { | ||
| case "1": NavFrame.Navigate(typeof(FirstPage)); break; | ||
| case "2": NavFrame.Navigate(typeof(SecondPage)); break; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private void NavView_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| NavView.SelectedItem = NavView.MenuItems[0]; | ||
| } | ||
|
|
||
| private void NavFrame_Navigated(object sender, NavigationEventArgs e) | ||
| { | ||
| appTitleBar.IsBackButtonVisible = NavFrame.CanGoBack; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <Project Sdk="MSBuild.Sdk.Extras/3.0.23"> | ||
| <PropertyGroup> | ||
| <ToolkitComponentName>TitleBar</ToolkitComponentName> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Sets this up as a toolkit component's sample project --> | ||
| <Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" /> | ||
| <ItemGroup> | ||
| <None Remove="Assets\AppTitleBarIcon.png" /> | ||
| <None Remove="Assets\Avatar.png" /> | ||
| <None Remove="Assets\icon.png" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Content Include="Assets\AppTitleBarIcon.png"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Assets\Avatar.png"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Assets\icon.png"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| title: TitleBar | ||
| author: niels9001 | ||
| description: A control that provides a modern TitleBar | ||
| keywords: TitleBar, Control, Layout | ||
| dev_langs: | ||
| - csharp | ||
| category: Controls | ||
| subcategory: Layout | ||
| discussion-id: 0 | ||
| issue-id: 0 | ||
| icon: assets/icon.png | ||
| --- | ||
|
|
||
| The `TitleBar` provides an easy way to display a modern titlebar experience. The control handles all the required APIs to extend content into the titlebar area and set custom drag regions. The control is set up in a way that it handles the correct design guidelines while being flexible in what content to show. | ||
|
|
||
| > [!Sample TitleBarConfigSample] | ||
|
|
||
| > [!Sample TitleBarFullSample] | ||
|
|
||
| ## Using TitleBar in WASDK apps | ||
| If `AutoConfigureCustomTitleBar` is enabled, the `TitleBar` will make the required code-behind changes to make your content extend into the titlebar area and setting the correct caption background brushes. However, launching the app might briefly show the standard titlebar. To overcome this, make sure you set the following code in the `OnLaunched` method (in `App.xaml.cs`) or wherever you create your window: | ||
niels9001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```CS | ||
| currentWindow.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true; | ||
| currentWindow.AppWindow.TitleBar.ButtonBackgroundColor = Microsoft.UI.Colors.Transparent; | ||
| ` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ``` |
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.