Add custom titlebar to default Cs and Cpp WinUI template (#4035)

This change adds custom titlebnar to Cs and Cpp template. As a result, any hello world WinUI app created via the template has custom titlebar already applied to it. This provides a better experience for developers as default option takes care of styling of the window. It works better with overall theming.

This is a better experience right out of the box. Similar default is followed by MAUI and Template Studio projects.
This commit is contained in:
Pratik Anand 2024-02-21 17:43:44 -08:00 коммит произвёл GitHub
Родитель 9664ff3740
Коммит 32ff3b99fa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
14 изменённых файлов: 47 добавлений и 13 удалений

Просмотреть файл

@ -26,6 +26,7 @@ namespace $rootnamespace$
public $safeitemname$()
{
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true; // provides default WinUI custom title bar experience
}
}
}

Просмотреть файл

@ -10,6 +10,7 @@ namespace winrt::$rootnamespace$::implementation
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
ExtendsContentIntoTitleBar(true); // provides default WinUI custom title bar experience
}
int32_t MyProperty();

Просмотреть файл

@ -8,7 +8,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackPanel Margin="20,5,0,0" Height="32" HorizontalAlignment="Stretch">
<TextBlock>$safeitemname$</TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</StackPanel>
</Window>

Просмотреть файл

@ -8,7 +8,12 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackPanel Margin="20,5,0,0" Height="32" HorizontalAlignment="Stretch">
<TextBlock>$safeitemname$</TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</StackPanel>
</Window>

Просмотреть файл

@ -26,6 +26,7 @@ namespace $safeprojectname$
public MainWindow()
{
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true; // provides default WinUI custom title bar experience
}
private void myButton_Click(object sender, RoutedEventArgs e)

Просмотреть файл

@ -8,7 +8,12 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackPanel Margin="20,5,0,0" Height="32" HorizontalAlignment="Stretch">
<TextBlock>$safeitemname$</TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</StackPanel>
</Window>

Просмотреть файл

@ -26,6 +26,7 @@ namespace $safeprojectname$
public MainWindow()
{
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true; // provides default WinUI custom title bar experience
}
private void myButton_Click(object sender, RoutedEventArgs e)

Просмотреть файл

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

Просмотреть файл

@ -23,6 +23,8 @@ namespace $safeprojectname$
public UnitTestAppWindow()
{
this.InitializeComponent();
}
this.ExtendsContentIntoTitleBar = true; // provides default WinUI custom title bar experience
}
}
}

Просмотреть файл

@ -10,6 +10,7 @@ namespace winrt::$safeprojectname$::implementation
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
ExtendsContentIntoTitleBar(true); // provides default WinUI custom title bar experience
}
int32_t MyProperty();

Просмотреть файл

@ -8,7 +8,12 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackPanel Margin="20,5,0,0" Height="32" HorizontalAlignment="Stretch">
<TextBlock>$safeitemname$</TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</StackPanel>
</Window>

Просмотреть файл

@ -10,6 +10,7 @@ namespace winrt::$safeprojectname$::implementation
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
ExtendsContentIntoTitleBar(true); // provides default WinUI custom title bar experience
}
int32_t MyProperty();

Просмотреть файл

@ -8,7 +8,12 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackPanel Margin="20,5,0,0" Height="32" HorizontalAlignment="Stretch">
<TextBlock>$safeitemname$</TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</StackPanel>
</Window>

Просмотреть файл

@ -14,6 +14,6 @@ namespace winrt::$safeprojectname$::implementation
{
MainWindow::MainWindow()
{
ExtendsContentIntoTitleBar(true); // provides default WinUI custom title bar experience
}
}