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

[Windows] Add TitleBar Control #23019

Merged
merged 36 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9054b27
Custom titlebar control support spike
Apr 24, 2024
f0b09d4
handle titlebar hit test elements automatically
Apr 25, 2024
d4c7771
sample
Apr 26, 2024
cb97540
Added TitleBar property to Window: you can now set titlebar propertie…
Jun 7, 2024
4fe2744
Add inactive colors for background + foreground
Jun 11, 2024
e90a549
Fix issue w/ titlebar unhook on window close
Jun 11, 2024
c213528
Added `Window.SetTitleBar` function to set the window titlebar. This …
Jun 12, 2024
3159eaa
Revert some changes
Jun 12, 2024
8876b49
Revert changes
Jun 12, 2024
cff8f6a
Merge branch 'main' into foda/NewTitlebar
jsuarezruiz Jun 13, 2024
590958a
Error checkAdditional error checks for page nav
Jun 14, 2024
92d8d1e
Merge branch 'foda/NewTitlebar' of https://github.com/dotnet/maui int…
Jun 14, 2024
e21eb87
Update ITitlebar interface
Jun 18, 2024
3b9f756
Titlebar control is now a TemplatedView
Jun 19, 2024
5c55be8
Remove `SetTitlebar` API
Jun 20, 2024
c9bf29a
Remove child
Jun 20, 2024
0e4c295
Use pattern matching
Jun 20, 2024
f577e68
Merge
Jun 28, 2024
c11b828
Add some docs
Jul 1, 2024
e7a4f0f
Merge branch 'main' into foda/NewTitlebar
Foda Jul 8, 2024
1b4e216
Fix missing publicapi bits
Jul 10, 2024
e5ee751
More public api bits
Jul 10, 2024
af77410
Missed some
Jul 10, 2024
af976d7
Fix use of content presenter
Jul 11, 2024
ec2d71c
Adjust passthrough logic
Jul 11, 2024
6ac872e
Fix titlebar height adjust for caption buttons
Jul 11, 2024
6ef2430
Fix override of default template not working
Jul 11, 2024
ab892f2
Cleanup
Jul 12, 2024
9965a8b
Fix default control template not being applied
Jul 15, 2024
bfbfdae
Fix missing API for tizen
Jul 16, 2024
c8832e8
Fix sample issue
Jul 18, 2024
4095fa4
Fix missing title + icon when titlebar is not fully set
Jul 19, 2024
e5a4017
Add IgnoreSafeArea for macOS
Jul 19, 2024
ca81c67
Tizen
Jul 22, 2024
bfeebf6
Fix titlebar being set on window creation w/ template selector
Jul 23, 2024
bd0bb39
Comment out templates
Jul 24, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:windows="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;assembly=Microsoft.Maui.Controls"
x:Class="Maui.Controls.Sample.Pages.WindowsTitleBarPage"
Title="WebView Platform-Specifics">
<Grid
ColumnDefinitions="*,*">
<VerticalStackLayout
Spacing="16"
Margin="16"
Grid.Column="0">

<Label
Text="Content Options"
FontSize="24"/>

<HorizontalStackLayout>
<CheckBox
x:Name="SetIconCheckBox"
IsChecked="False"
CheckedChanged="SetIconCheckBox_CheckedChanged"/>
<Label
Text="Set Icon"
VerticalOptions="Center"/>
</HorizontalStackLayout>

<Entry
x:Name="TitleTextBox"
Placeholder="Title Text"
HorizontalOptions="Start"
Text="{Binding Title, Mode=TwoWay}"
WidthRequest="120" />
<Entry
x:Name="SubtitleTextBox"
Placeholder="Subtitle Text"
HorizontalOptions="Start"
Text="{Binding Subtitle, Mode=TwoWay}"
WidthRequest="120" />

<HorizontalStackLayout>
<CheckBox
x:Name="LeadingContentCheckBox"
IsChecked="False"
CheckedChanged="LeadingCheckBox_CheckedChanged"/>
<Label
Text="Leading Content"
VerticalOptions="Center"/>
</HorizontalStackLayout>

<HorizontalStackLayout>
<CheckBox
x:Name="ContentCheckBox"
IsChecked="False"
CheckedChanged="ContentCheckBox_CheckedChanged"/>
<Label
Text="Content"
VerticalOptions="Center"/>
</HorizontalStackLayout>

<HorizontalStackLayout>
<CheckBox
x:Name="TrailingContentCheckBox"
IsChecked="False"
CheckedChanged="TrailingCheckBox_CheckedChanged"/>
<Label
Text="Trailing Content"
VerticalOptions="Center"/>
</HorizontalStackLayout>

<HorizontalStackLayout>
<CheckBox
x:Name="TallModeCheckBox"
IsChecked="False"
CheckedChanged="TallModeCheckBox_CheckedChanged"/>
<Label
Text="Tall TitleBar"
VerticalOptions="Center"/>
</HorizontalStackLayout>

<HorizontalStackLayout>
<CheckBox
IsChecked="{Binding ShowTitleBar, Mode=TwoWay}"/>
<Label
Text="Show TitleBar"
VerticalOptions="Center"/>
</HorizontalStackLayout>
</VerticalStackLayout>

<VerticalStackLayout
Spacing="16"
Margin="16"
Grid.Column="1">
<Label
Text="Color Options"
FontSize="24"/>

<HorizontalStackLayout
Spacing="8">
<Entry
x:Name="ColorTextBox"
Placeholder="Green"
HorizontalOptions="Start"
WidthRequest="120" />
<Button
x:Name="ColorButton"
Text="Set Color"
Clicked="ColorButton_Clicked" />
</HorizontalStackLayout>

<HorizontalStackLayout
Spacing="8">
<Entry
x:Name="InactiveColorTextBox"
Placeholder="Green"
HorizontalOptions="Start"
WidthRequest="120" />
<Button
x:Name="InactiveColorButton"
Text="Set Inactive Background Color"
Clicked="InactiveColorButton_Clicked" />
</HorizontalStackLayout>

<HorizontalStackLayout
Spacing="8">
<Entry
x:Name="ForegroundColorTextBox"
Placeholder="Green"
HorizontalOptions="Start"
WidthRequest="120" />
<Button
x:Name="ForegroundColorButton"
Text="Set Foreground Color"
Clicked="ForegroundColorButton_Clicked" />
</HorizontalStackLayout>

<HorizontalStackLayout
Spacing="8">
<Entry
x:Name="InactiveForegroundColorTextBox"
Placeholder="Green"
HorizontalOptions="Start"
WidthRequest="120" />
<Button
x:Name="InactiveForegroundColorButton"
Text="Set Inactive Foreground Color"
Clicked="InactiveForegroundColorButton_Clicked" />
</HorizontalStackLayout>
</VerticalStackLayout>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using System;
using Maui.Controls.Sample.ViewModels;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Pages
{
public partial class WindowsTitleBarPage : ContentPage
{
TitleBarSampleViewModel _viewModel;
TitleBar _customTitleBar;

public WindowsTitleBarPage()
{
InitializeComponent();

_viewModel = new TitleBarSampleViewModel();
BindingContext = _viewModel;

string titleBarXaml =
"""
<TitleBar
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
Title="{Binding Title}"
Subtitle="{Binding Subtitle}"
IsVisible="{Binding ShowTitleBar}"/>
""";

_customTitleBar = new TitleBar().LoadFromXaml(titleBarXaml);
_customTitleBar.BindingContext = _viewModel;
}

protected override void OnAppearing()
{
base.OnAppearing();
Window.TitleBar = _customTitleBar;
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be removed again when the page closes?
It does feel slightly weird to have the contentpage mess with the app-wide window. That might be more appropriate to use AppShell for instead, since that requires to be the root of the window content and hosts pages inside it.

}

private void SetIconCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_customTitleBar.Icon = "tb_appicon.png";
}
else
{
_customTitleBar.Icon = "";
}
}

private void ColorButton_Clicked(object sender, EventArgs e)
{
if (Microsoft.Maui.Graphics.Color.TryParse(ColorTextBox.Text, out var color))
{
_customTitleBar.BackgroundColor = color;
}
}

private void InactiveColorButton_Clicked(object sender, EventArgs e)
{
if (Microsoft.Maui.Graphics.Color.TryParse(InactiveColorTextBox.Text, out var color))
{
_customTitleBar.InactiveBackgroundColor = color;
}
}

private void ForegroundColorButton_Clicked(object sender, EventArgs e)
{
if (Microsoft.Maui.Graphics.Color.TryParse(ForegroundColorTextBox.Text, out var color))
{
_customTitleBar.ForegroundColor = color;
}
}

private void InactiveForegroundColorButton_Clicked(object sender, EventArgs e)
{
if (Microsoft.Maui.Graphics.Color.TryParse(InactiveForegroundColorTextBox.Text, out var color))
{
_customTitleBar.InactiveForegroundColor = color;
}
}

private void LeadingCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_customTitleBar.LeadingContent = new Button()
{
Text = "Leading"
};
}
else
{
_customTitleBar.LeadingContent = null;
}
}

private void ContentCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_customTitleBar.Content = new Entry()
{
Placeholder = "Search",
MinimumWidthRequest = 200,
MaximumWidthRequest = 500,
HeightRequest = 32
};
}
else
{
_customTitleBar.Content = null;
}
}

private void TrailingCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_customTitleBar.TrailingContent = new Button()
{
Text = "Trailing"
};
}
else
{
_customTitleBar.TrailingContent = null;
}
}

private void TallModeCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_customTitleBar.HeightRequest = 48;
}
else
{
_customTitleBar.HeightRequest = 32;
}
}
}
}
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
Expand Up @@ -135,6 +135,9 @@ protected override IEnumerable<SectionModel> CreateItems()
new SectionModel(typeof(WindowsReadingOrderPage), "Text Reading Order",
"This WinUI platform-specific enables the reading order (left-to-right or right-to-left) of bidirectional text in Entry, Editor, and Label instances to be detected dynamically."),

new SectionModel(typeof(WindowsTitleBarPage), "TitleBar",
"This WinUI platform-specific enables TitleBar customization."),

new SectionModel(typeof(WindowsRefreshViewPage), "RefreshView Pull Direction",
"This WinUI platform-specific enables the pull direction of a RefreshView to be changed to match the orientation of the scrollable control that's displaying data."),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Maui.Controls.Sample.ViewModels.Base;

namespace Maui.Controls.Sample.ViewModels
Copy link
Contributor

@MartyIX MartyIX Jul 12, 2024

Choose a reason for hiding this comment

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

Would it be better to use file-scope namespaces in new files?

{
public class TitleBarSampleViewModel : BaseViewModel
{
private string _title = "";
public string Title
{
get { return _title; }
set
{
_title = value;
OnPropertyChanged();
}
}

private string _subtitle = "";
public string Subtitle
{
get { return _subtitle; }
set
{
_subtitle = value;
OnPropertyChanged();
}
}

private bool _showTitleBar = true;
public bool ShowTitleBar
{
get { return _showTitleBar; }
set
{
_showTitleBar = value;
OnPropertyChanged();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Controls.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;$(_MauiDotNetTfm);$(MauiPlatforms)</TargetFrameworks>
Expand Down
Loading
Loading