Skip to content

Commit c991fbd

Browse files
authored
Merge pull request #102 from egvijayanand/working
Window TitleBar for Desktop
2 parents 66ad292 + b115de4 commit c991fbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1693
-2
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Vijay Anand E G
3+
Copyright (c) 2021-2024 Vijay Anand E G
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Made available in the `src\NET_9\` directory:
1616
|`EmbeddediOS`|.NET MAUI Page embedded in a .NET 9 for iOS App <br /> Refer to this [.NET MAUI - Native Embedding](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) article for working with this sample|
1717
|`EmbeddedWindows`|.NET MAUI Page embedded in a Native WinUI 3 App <br /> Refer to this [.NET MAUI - Native Embedding](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) article for working with this sample|
1818
|`MapsApp`|Using .NET MAUI [CommunityToolkit.Maui.Maps](https://www.nuget.org/packages/CommunityToolkit.Maui.Maps) embedded in a Native WinUI 3 App <br /> Refer to this [.NET MAUI Community Toolkit Maps in WinUI 3 App](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) article for working with this sample|
19-
|`HybridWebViewApp`|A sample .NET MAUI App showcasing the features of the new [HybridWebView](https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#hybridwebview) control. <br /> Refer to this [Exploring .NET MAUI 9: HybridWebView Features](https://egvijayanand.in/2024/10/04/exploring-dotnet-maui-9-hybridwebview-features/) article for working with this sample|
19+
|`HybridWebViewApp`|A sample app showcasing the features of the new [HybridWebView](https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#hybridwebview) control. <br /> Refer to this [Exploring .NET MAUI 9: HybridWebView](https://egvijayanand.in/2024/10/04/exploring-dotnet-maui-9-hybridwebview-features/) article for working with this sample|
2020
|`WinUIBlazor`|.NET MAUI `BlazorWebView` embedded in a Native WinUI 3 App, making it as a Blazor Hybrid app <br /> Refer to this [.NET MAUI - Blazor Hybrid - WinUI 3](https://egvijayanand.in/2023/03/29/dotnet-maui-blazor-hybrid-winui-3/) article for working with this sample|
21+
|`TitleBarApp`|A sample app showcasing the features of the new [TitleBar](https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#titlebar-for-windows) control. <br /> Refer to this [What's New in .NET MAUI 9: Window TitleBar](https://egvijayanand.in/2024/12/04/what-is-new-in-dotnet-maui-9-window-titlebar/) article for working with this sample|
2122

2223
### .NET MAUI 8 Samples
2324

src/NET_9/TitleBarApp/App.xaml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Application
3+
x:Class="TitleBarApp.App"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
7+
xmlns:local="clr-namespace:TitleBarApp"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
<Application.Resources>
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<ResourceDictionary Source="Resources/Colors.xaml" />
14+
<ResourceDictionary Source="Resources/Styles.xaml" />
15+
</ResourceDictionary.MergedDictionaries>
16+
<!-- Additional Styles -->
17+
<x:Double x:Key="ItemSpacing">10</x:Double>
18+
<x:String x:Key="BoldFont">OS600</x:String>
19+
20+
<Style
21+
ApplyToDerivedTypes="True"
22+
TargetType="StackBase">
23+
<Setter Property="Spacing" Value="{StaticResource ItemSpacing}" />
24+
</Style>
25+
26+
<Style
27+
x:Key="Title"
28+
TargetType="Label">
29+
<Setter Property="FontFamily" Value="{StaticResource AppFont}" />
30+
<Setter Property="FontSize" Value="16" />
31+
<Setter Property="TextColor" Value="{StaticResource White}" />
32+
<Setter Property="HorizontalOptions" Value="Center" />
33+
<Setter Property="VerticalOptions" Value="Center" />
34+
</Style>
35+
36+
<Style
37+
x:Key="AppTitle"
38+
BasedOn="{StaticResource Title}"
39+
TargetType="Label">
40+
<Setter Property="FontFamily" Value="{StaticResource BoldFont}" />
41+
<Setter Property="FontSize" Value="18" />
42+
</Style>
43+
44+
<Style
45+
x:Key="MauiLabel"
46+
TargetType="Label">
47+
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource Primary}}" />
48+
</Style>
49+
50+
<Style
51+
x:Key="Action"
52+
TargetType="Button">
53+
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource BackgroundLight}}" />
54+
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource TextDark}, Light={StaticResource TextLight}}" />
55+
<Setter Property="FontFamily" Value="{StaticResource AppFont}" />
56+
<Setter Property="FontSize" Value="{StaticResource AppFontSize}" />
57+
<Setter Property="Padding" Value="14,10" />
58+
</Style>
59+
60+
<Style
61+
x:Key="PrimaryAction"
62+
BasedOn="{StaticResource Action}"
63+
TargetType="Button">
64+
<Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
65+
<Setter Property="FontAttributes" Value="Bold" />
66+
<Setter Property="TextColor" Value="{StaticResource White}" />
67+
</Style>
68+
</ResourceDictionary>
69+
</Application.Resources>
70+
</Application>

src/NET_9/TitleBarApp/App.xaml.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace TitleBarApp;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
UserAppTheme = PlatformAppTheme;
10+
}
11+
12+
protected override Window CreateWindow(IActivationState? activationState)
13+
=> new MainWindow();
14+
}

src/NET_9/TitleBarApp/AppShell.xaml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="TitleBarApp.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:vw="clr-namespace:TitleBarApp.Views"
7+
FlyoutBehavior="Locked">
8+
<!--
9+
The overall app visual hierarchy is defined here, along with navigation.
10+
Ensure atleast a Flyout item or a TabBar is defined for Shell to work
11+
-->
12+
<Shell.Resources>
13+
<!--
14+
Define the resources to be used within this Shell visual hierarchy
15+
-->
16+
</Shell.Resources>
17+
<!--
18+
When the Flyout is visible this defines the content to display in the flyout.
19+
FlyoutDisplayOptions="AsMultipleItems" will create a separate flyout item for each child element
20+
-->
21+
<FlyoutItem Title="No TitleBar">
22+
<ShellContent
23+
ContentTemplate="{DataTemplate vw:MainPage}"
24+
Route="home" />
25+
</FlyoutItem>
26+
<FlyoutItem Title="TitleBar (XAML)">
27+
<ShellContent
28+
ContentTemplate="{DataTemplate vw:XamlPage}"
29+
Route="xaml" />
30+
</FlyoutItem>
31+
<FlyoutItem Title="TitleBar (C#)">
32+
<ShellContent
33+
ContentTemplate="{DataTemplate vw:CSharpPage}"
34+
Route="csharp" />
35+
</FlyoutItem>
36+
<!--
37+
When the Flyout is visible this will be a menu item you can tie a click behavior to
38+
-->
39+
<!--
40+
<MenuItem
41+
Clicked="OnMenuItemClicked"
42+
Text="Logout" />
43+
-->
44+
<!--
45+
TabBar lets you define content that won't show up in a Flyout menu. When this content is active
46+
the flyout menu won't be available. This is useful for creating areas of the application where
47+
you don't want users to be able to navigate away from. If you would like to navigate to this
48+
content you can do so by calling
49+
await Shell.Current.GoToAsync("//login");
50+
-->
51+
<!--
52+
<TabBar>
53+
<ShellContent
54+
ContentTemplate="{DataTemplate local:LoginPage}"
55+
Route="login" />
56+
</TabBar>
57+
-->
58+
<!-- Optional Templates
59+
// These may be provided inline as below or as separate classes.
60+
61+
// This header appears at the top of the Flyout
62+
<Shell.FlyoutHeaderTemplate>
63+
<DataTemplate>
64+
<Grid>ContentHere</Grid>
65+
</DataTemplate>
66+
</Shell.FlyoutHeaderTemplate>
67+
68+
// ItemTemplate is for ShellItems as displayed in a Flyout
69+
<Shell.ItemTemplate>
70+
<DataTemplate>
71+
<ContentView>
72+
Bindable Properties: Title, Icon
73+
</ContentView>
74+
</DataTemplate>
75+
</Shell.ItemTemplate>
76+
77+
// MenuItemTemplate is for MenuItems as displayed in a Flyout
78+
<Shell.MenuItemTemplate>
79+
<DataTemplate>
80+
<ContentView>
81+
Bindable Properties: Text, Icon
82+
</ContentView>
83+
</DataTemplate>
84+
</Shell.MenuItemTemplate>
85+
86+
// This footer appears at the bottom of the Flyout
87+
<Shell.FlyoutFooterTemplate>
88+
<DataTemplate>
89+
<Grid>ContentHere</Grid>
90+
</DataTemplate>
91+
</Shell.FlyoutFooterTemplate>
92+
-->
93+
</Shell>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace TitleBarApp
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
4+
<MauiVersion>9.*</MauiVersion>
5+
</PropertyGroup>
6+
</Project>

src/NET_9/TitleBarApp/Imports.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// .NET MAUI Markup
2+
global using CommunityToolkit.Maui.Markup;
3+
4+
// MVVM Toolkit
5+
global using CommunityToolkit.Mvvm.ComponentModel;
6+
global using CommunityToolkit.Mvvm.Input;
7+
8+
global using TitleBarApp;
9+
global using TitleBarApp.Views;
10+
11+
// Shared Toolkit
12+
global using VijayAnand.Toolkit.Markup;
13+
14+
// Static
15+
global using static CommunityToolkit.Maui.Markup.GridRowsColumns;
16+
global using static Microsoft.Maui.Graphics.Colors;
17+
global using static VijayAnand.Toolkit.Markup.ResourceHelper;

src/NET_9/TitleBarApp/MainWindow.xaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Window
2+
x:Class="TitleBarApp.MainWindow"
3+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:local="clr-namespace:TitleBarApp"
6+
Title="TitleBarApp">
7+
<!-- Page is the Content Property of the Window -->
8+
<local:AppShell />
9+
</Window>
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace TitleBarApp
2+
{
3+
public partial class MainWindow : Window
4+
{
5+
public MainWindow()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
public MainWindow(Page page) : base(page)
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

src/NET_9/TitleBarApp/MauiProgram.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace TitleBarApp
4+
{
5+
public static partial class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder.UseMauiApp<App>()
11+
.UseMauiCommunityToolkitMarkup()
12+
.ConfigureFonts(fonts =>
13+
{
14+
fonts.AddFont("OpenSans-Regular.ttf", "OS400");
15+
fonts.AddFont("OpenSans-SemiBold.ttf", "OS600");
16+
fonts.AddFont("fa-solid-900.ttf", "FAS");
17+
});
18+
19+
#if DEBUG
20+
builder.Logging.AddDebug();
21+
#endif
22+
23+
return builder.Build();
24+
}
25+
}
26+
}

src/NET_9/TitleBarApp/MyWindow.xaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Window
3+
x:Class="TitleBarApp.MyWindow"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:vw="clr-namespace:TitleBarApp.Views"
7+
Title="MyApp">
8+
<Window.Page>
9+
<vw:MainPage />
10+
</Window.Page>
11+
<Window.TitleBar>
12+
<!-- Can also be defined separately and included here -->
13+
<!--<vw:MyTitleBar />-->
14+
<TitleBar
15+
BackgroundColor="{StaticResource Primary}"
16+
ForegroundColor="{StaticResource White}"
17+
HeightRequest="48">
18+
<!-- Customized Title and Subtitle -->
19+
<TitleBar.LeadingContent>
20+
<Grid
21+
Margin="20,0,0,0"
22+
ColumnDefinitions="Auto,Auto,Auto"
23+
ColumnSpacing="15"
24+
VerticalOptions="Center">
25+
<Image
26+
HeightRequest="16"
27+
Source="dotnet_bot.png"
28+
WidthRequest="16" />
29+
<Label
30+
Grid.Column="1"
31+
Style="{StaticResource AppTitle}"
32+
Text="MyApp" />
33+
<Label
34+
Grid.Column="2"
35+
Style="{StaticResource Title}"
36+
Text="Home" />
37+
</Grid>
38+
</TitleBar.LeadingContent>
39+
<TitleBar.Content>
40+
<SearchBar
41+
BackgroundColor="{StaticResource White}"
42+
HorizontalOptions="Fill"
43+
MaximumWidthRequest="300"
44+
Placeholder="Search"
45+
VerticalOptions="Center" />
46+
</TitleBar.Content>
47+
<TitleBar.TrailingContent>
48+
<ImageButton
49+
Background="Transparent"
50+
BorderWidth="0"
51+
HeightRequest="36"
52+
WidthRequest="36">
53+
<ImageButton.Source>
54+
<FontImageSource
55+
FontFamily="FAS"
56+
Glyph="&#xf013;"
57+
Size="18" />
58+
</ImageButton.Source>
59+
</ImageButton>
60+
</TitleBar.TrailingContent>
61+
</TitleBar>
62+
</Window.TitleBar>
63+
</Window>
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace TitleBarApp
2+
{
3+
public partial class MyWindow : Window
4+
{
5+
public MyWindow()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
public MyWindow(Page page) : base(page)
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35" />
4+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace TitleBarApp
6+
{
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
11+
}
12+
}

0 commit comments

Comments
 (0)