dotnet / dotnet/maui

Button Horizontal and Vertical TextAlignment

Open
#10,463 12 comments 22 reactions 0 assignees View on GitHub
area-controls-button partner/cat 😻 proposal/open t/enhancement ☀️
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

I would love button supports HorizontalTextAlignment (and Vertical) as Label does.

### Public API Changes

```xaml

```

### Intended Use-Case

I had need the handler in android and i made it:

```csharp
protected override void ConnectHandler(MaterialButton platformView)
{
base.ConnectHandler(platformView);

OnTextAlignmentPropertyChanged();
}

public override void UpdateValue(string property)
{
base.UpdateValue(property);
if (property == ButtonControl.HorizontalTextAlignmentProperty.PropertyName || property == ButtonControl.VerticalTextAlignmentProperty.PropertyName)
OnTextAlignmentPropertyChanged();
}

private void OnTextAlignmentPropertyChanged()
{
if (VirtualView is ButtonControl buttonControl)
{
GravityFlag horizontalFlag = buttonControl.HorizontalTextAlignment switch
{
TextAlignment.Start => GravityFlag.Left,
TextAlignment.Center => GravityFlag.CenterHorizontal,
TextAlignment.End => GravityFlag.Right,
_ => GravityFlag.Center
};
GravityFlag verticalFlag = buttonControl.VerticalTextAlignment switch
{
TextAlignment.Start => GravityFlag.Top,
TextAlignment.Center => GravityFlag.CenterVertical,
TextAlignment.End => GravityFlag.Bottom,
_ => GravityFlag.Center
};
PlatformView.Gravity = horizontalFlag | verticalFlag;
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start at ButtonControl and compare its API with the Label text-alignment implementation, then inspect the platform button handlers, including the Android handler described in the issue. The work is complete when the public XAML properties are supported and horizontal and vertical alignment produce the requested button text positioning across the relevant platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend, mobile-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.