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

[Experiment] TitleBar #459

Merged
merged 41 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0fcb076
Init
niels9001 Jul 4, 2023
f75784b
Remove files
niels9001 Jul 5, 2023
a39a294
Delete BlankPage1.xaml.cs
niels9001 Jul 5, 2023
f61434b
Improve samples
niels9001 Jul 5, 2023
7b82a95
XAML styling
niels9001 Jul 5, 2023
cb24ed5
UpdateCaptionButtons
ghost1372 Jul 6, 2023
b4529e4
Remove GetAppWindow() and Use Window.AppWindow
ghost1372 Jul 6, 2023
8094a33
Merge pull request #462 from ghost1372/TitleBar-AppWindow
niels9001 Jul 6, 2023
2015162
Merge branch 'niels9001/titlebar-experiment' into TitleBar-CaptionBut…
ghost1372 Jul 6, 2023
3e63cd7
Merge pull request #461 from ghost1372/TitleBar-CaptionButtons
niels9001 Jul 7, 2023
571f33c
Improve reset
niels9001 Jul 7, 2023
8f06ff3
Merge branch 'niels9001/titlebar-experiment' of https://github.com/Co…
niels9001 Jul 7, 2023
56fc9de
Address feedback
niels9001 Jul 17, 2023
6b9887c
Update TitleBar.md
niels9001 Jul 17, 2023
8c959e7
Fix CI
niels9001 Jul 17, 2023
4dfd4ae
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Jul 19, 2023
4337e64
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Jul 24, 2023
65f7e15
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Aug 21, 2023
0972be5
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Sep 22, 2023
8e84104
Fix PaneButton
ghost1372 Nov 5, 2023
b21d4c3
Merge pull request #506 from ghost1372/Fix-TitleBar
niels9001 Nov 5, 2023
6bec342
Fix Drag regions
ghost1372 Nov 5, 2023
f748819
Remove WindowNative and use AppWindow.Id
ghost1372 Nov 5, 2023
489cf3a
Merge pull request #507 from ghost1372/Fix-TitleBar2
niels9001 Nov 6, 2023
4a7d568
Update components/TitleBar/samples/TitleBar.md
niels9001 Nov 6, 2023
3b37fe5
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Nov 6, 2023
e19de6e
Fix TitleBar Drag Region
ghost1372 Nov 6, 2023
c8ba80c
Use WASDK v1.4 new Custom TitleBar API and Simplify Calculating Rects
ghost1372 Nov 11, 2023
27f440a
Remove unused Codes
ghost1372 Nov 11, 2023
abe0fe3
Move GetRasterizationScaleForElement out of loop
ghost1372 Nov 11, 2023
c0e54a6
Add ContextMenu Support
ghost1372 Nov 13, 2023
3ef7c07
Update TitleBar.WASDK.cs
ghost1372 Nov 20, 2023
4c4f776
Merge pull request #508 from ghost1372/Fix-TitleBar3
niels9001 Nov 22, 2023
b71ccbb
Add Missing #if WINAPPSDK
ghost1372 Nov 30, 2023
91a032c
Merge pull request #513 from ghost1372/niels9001/titlebar-experiment
niels9001 Nov 30, 2023
c4d5b38
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Feb 20, 2024
2cb787e
Merge branch 'main' into niels9001/titlebar-experiment
niels9001 Apr 22, 2024
cb83879
Fixed nullability errors
Arlodotexe Apr 25, 2024
4fb3530
Fixed invalid reference in XML comment
Arlodotexe Apr 25, 2024
396c61a
Restrict TitleBar MultiTargets to uwp and wasdk
Arlodotexe Apr 25, 2024
aa780a5
Remove empty example test methods
Arlodotexe May 18, 2024
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
3 changes: 3 additions & 0 deletions components/TitleBar/OpenSolution.bat
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.
Binary file added components/TitleBar/samples/Assets/Avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added components/TitleBar/samples/Assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions components/TitleBar/samples/Dependencies.props
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>
18 changes: 18 additions & 0 deletions components/TitleBar/samples/SamplePages/FirstPage.xaml
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>
15 changes: 15 additions & 0 deletions components/TitleBar/samples/SamplePages/FirstPage.xaml.cs
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();
}
}
18 changes: 18 additions & 0 deletions components/TitleBar/samples/SamplePages/SecondPage.xaml
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 components/TitleBar/samples/SamplePages/SecondPage.xaml.cs
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();
}
}
88 changes: 88 additions & 0 deletions components/TitleBar/samples/SamplePages/ShellPage.xaml
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="&#xE77B;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem Text="Settings">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE713;" />
</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="&#xE787;" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem Content="Second item"
Tag="2">
<muxc:NavigationViewItem.Icon>
<FontIcon Glyph="&#xE7C5;" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
</muxc:NavigationView.MenuItems>
<Frame x:Name="NavFrame"
Navigated="NavFrame_Navigated" />
</muxc:NavigationView>
</Grid>
</Page>
56 changes: 56 additions & 0 deletions components/TitleBar/samples/SamplePages/ShellPage.xaml.cs
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;
niels9001 marked this conversation as resolved.
Show resolved Hide resolved
}
}
25 changes: 25 additions & 0 deletions components/TitleBar/samples/TitleBar.Samples.csproj
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>
28 changes: 28 additions & 0 deletions components/TitleBar/samples/TitleBar.md
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;
`
Copy link
Contributor

Choose a reason for hiding this comment

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

```


Loading
Loading