From bde325ddf9dbcf129cf898d07e7d45e9baf9070b Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Wed, 13 Nov 2024 01:17:06 +0200 Subject: [PATCH 1/2] Add TitleBar --- samples/ControlGallery/AppShell.razor | 43 +++--- .../Elements/TitleBar.generated.cs | 126 ++++++++++++++++++ .../Elements/Window.generated.cs | 5 + .../Properties/AttributeInfo.cs | 1 + 4 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 src/BlazorBindings.Maui/Elements/TitleBar.generated.cs diff --git a/samples/ControlGallery/AppShell.razor b/samples/ControlGallery/AppShell.razor index 1b8771db..219effb7 100644 --- a/samples/ControlGallery/AppShell.razor +++ b/samples/ControlGallery/AppShell.razor @@ -14,23 +14,35 @@ @using ControlGallery.Views.Menus + + + + + + + + + - @*Present data*@ + @*Present data*@ - @*Initiate commands*@ + @*Initiate commands*@ - @*Set values*@ + @*Set values*@ @@ -38,11 +50,11 @@ - @*Edit text*@ + @*Edit text*@ - @*Display collections*@ + @*Display collections*@ @@ -55,12 +67,12 @@ - @*Layouts*@ + @*Layouts*@ - @*Shell*@ + @*Shell*@ - @*Navigation*@ + @*Navigation*@ - @*Other*@ + @*Other*@ - @if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst) - { - - - - } + @if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst) + { + + + + } + @code { diff --git a/src/BlazorBindings.Maui/Elements/TitleBar.generated.cs b/src/BlazorBindings.Maui/Elements/TitleBar.generated.cs new file mode 100644 index 00000000..49fa185a --- /dev/null +++ b/src/BlazorBindings.Maui/Elements/TitleBar.generated.cs @@ -0,0 +1,126 @@ +// +// This code was generated by a BlazorBindings.Maui component generator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +using BlazorBindings.Core; +using MC = Microsoft.Maui.Controls; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Rendering; +using Microsoft.Maui; +using Microsoft.Maui.Graphics; +using System.Threading.Tasks; + +#pragma warning disable MBB001 + +namespace BlazorBindings.Maui.Elements +{ + /// + /// A control that provides title bar functionality for a window.

The standard title bar height is 32px, but can be set to a larger value.

The title bar can also be hidden by setting the property, which will cause the window content to be displayed in the title bar region. + ///
+ public partial class TitleBar : TemplatedView + { + static TitleBar() + { + RegisterAdditionalHandlers(); + } + + /// + /// Gets or sets the foreground color of the title bar. This color is used for the title and subtitle text. + /// + [Parameter] public Color ForegroundColor { get; set; } + /// + /// Gets or sets an optional icon image of the title bar. Icon images should be 16x16 pixels in size.

Setting this property to an empty value will hide the icon. + ///
+ [Parameter] public MC.ImageSource Icon { get; set; } + /// + /// Gets or sets the subtitle text of the title bar. The subtitle usually specifies the secondary information about the application or window + /// + [Parameter] public string Subtitle { get; set; } + /// + /// Gets or sets the title text of the title bar. The title usually specifies the name of the application or indicates the purpose of the window + /// + [Parameter] public string Title { get; set; } + /// + /// Gets or sets a control that represents the content.

This content is centered in the title bar, and is allocated the remaining space between the leading and trailing content.


Views set here will block all input to the title bar region and handle input directly. + ///
+ [Parameter] public RenderFragment Content { get; set; } + /// + /// Gets or sets a control that represents the leading content.

The leading content follows the optional and is aligned to the left or right of the title bar, depending on the . Views set here will be allocated as much space as they require.

Views set here will block all input to the title bar region and handle input directly. + ///
+ [Parameter] public RenderFragment LeadingContent { get; set; } + [Parameter] public RenderFragment PassthroughElements { get; set; } + /// + /// Gets or sets a control that represents the trailing content.

The trailing content is aligned to the right or left of the title bar, depending on the . Views set here will be allocated as much space as they require.

Views set here will block all input to the title bar region and handle input directly. + ///
+ [Parameter] public RenderFragment TrailingContent { get; set; } + + public new MC.TitleBar NativeControl => (MC.TitleBar)((BindableObject)this).NativeControl; + + protected override MC.TitleBar CreateNativeElement() => new(); + + protected override void HandleParameter(string name, object value) + { + switch (name) + { + case nameof(ForegroundColor): + if (!Equals(ForegroundColor, value)) + { + ForegroundColor = (Color)value; + NativeControl.ForegroundColor = ForegroundColor; + } + break; + case nameof(Icon): + if (!Equals(Icon, value)) + { + Icon = (MC.ImageSource)value; + NativeControl.Icon = Icon; + } + break; + case nameof(Subtitle): + if (!Equals(Subtitle, value)) + { + Subtitle = (string)value; + NativeControl.Subtitle = Subtitle; + } + break; + case nameof(Title): + if (!Equals(Title, value)) + { + Title = (string)value; + NativeControl.Title = Title; + } + break; + case nameof(Content): + Content = (RenderFragment)value; + break; + case nameof(LeadingContent): + LeadingContent = (RenderFragment)value; + break; + case nameof(PassthroughElements): + PassthroughElements = (RenderFragment)value; + break; + case nameof(TrailingContent): + TrailingContent = (RenderFragment)value; + break; + + default: + base.HandleParameter(name, value); + break; + } + } + + protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence) + { + base.RenderAdditionalElementContent(builder, ref sequence); + RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, Content, (x, value) => x.Content = (IView)value); + RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, LeadingContent, (x, value) => x.LeadingContent = (IView)value); + RenderTreeBuilderHelper.AddListContentProperty(builder, sequence++, PassthroughElements, x => x.PassthroughElements); + RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, TrailingContent, (x, value) => x.TrailingContent = (IView)value); + } + + static partial void RegisterAdditionalHandlers(); + } +} diff --git a/src/BlazorBindings.Maui/Elements/Window.generated.cs b/src/BlazorBindings.Maui/Elements/Window.generated.cs index b6b93da6..87a0e3c6 100644 --- a/src/BlazorBindings.Maui/Elements/Window.generated.cs +++ b/src/BlazorBindings.Maui/Elements/Window.generated.cs @@ -35,6 +35,7 @@ static Window() [Parameter] public double? X { get; set; } [Parameter] public double? Y { get; set; } [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment TitleBar { get; set; } [Parameter] public EventCallback OnSizeChanged { get; set; } [Parameter] public EventCallback OnModalPopped { get; set; } [Parameter] public EventCallback OnModalPopping { get; set; } @@ -131,6 +132,9 @@ protected override void HandleParameter(string name, object value) case nameof(ChildContent): ChildContent = (RenderFragment)value; break; + case nameof(TitleBar): + TitleBar = (RenderFragment)value; + break; case nameof(OnSizeChanged): if (!Equals(OnSizeChanged, value)) { @@ -282,6 +286,7 @@ protected override void RenderAdditionalElementContent(RenderTreeBuilder builder { base.RenderAdditionalElementContent(builder, ref sequence); RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, ChildContent, (x, value) => x.Page = (MC.Page)value); + RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, TitleBar, (x, value) => x.TitleBar = (ITitleBar)value); } static partial void RegisterAdditionalHandlers(); diff --git a/src/BlazorBindings.Maui/Properties/AttributeInfo.cs b/src/BlazorBindings.Maui/Properties/AttributeInfo.cs index cd8ad0ce..03b61a4c 100644 --- a/src/BlazorBindings.Maui/Properties/AttributeInfo.cs +++ b/src/BlazorBindings.Maui/Properties/AttributeInfo.cs @@ -150,6 +150,7 @@ [assembly: GenerateComponent(typeof(TemplatedPage), Exclude = [nameof(TemplatedPage.ControlTemplate)])] [assembly: GenerateComponent(typeof(TemplatedView))] [assembly: GenerateComponent(typeof(TimePicker), Exclude = [nameof(TimePicker.Time), nameof(TimePicker.TimeSelected)])] +[assembly: GenerateComponent(typeof(TitleBar))] [assembly: GenerateComponent(typeof(ToolbarItem))] [assembly: GenerateComponent(typeof(VerticalStackLayout))] [assembly: GenerateComponent(typeof(View))] From 6983568b83bd32a0fc16290a2d54e1979b4e1b61 Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Wed, 13 Nov 2024 18:52:51 +0200 Subject: [PATCH 2/2] format file --- samples/ControlGallery/AppShell.razor | 108 +++++++++++++------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/samples/ControlGallery/AppShell.razor b/samples/ControlGallery/AppShell.razor index 219effb7..f2999044 100644 --- a/samples/ControlGallery/AppShell.razor +++ b/samples/ControlGallery/AppShell.razor @@ -26,83 +26,83 @@ - + @*Present data*@ - - - + + + @*Initiate commands*@ - - - - + + + + @*Set values*@ - - - - - - + + + + + + @*Edit text*@ - - + + @*Display collections*@ - - - - - - - - - - - + + + + + + + + + + + @*Layouts*@ - - - + + + @*Shell*@ - - - - - + + + + + - + @*Navigation*@ - - - - + + + + @*Other*@ - - - - + + + + @if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst) { - - - + + + } - +