Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 445

Answer by Liyun Zhang - MSFT for Maui Button Cannot Left Align and Expand Button?

$
0
0

First of all, the xxxAndExpand attribute has been deprecated in MAUI, you can check the official document about the LayoutOptions.StartAndExpand Field.

But I tested your code on both xamarin and maui, the result were same.

The button will not expand to the frame unless I centre the text, which I don't want to do

Centering the text it the button't default behavior. If I change the StartAndExpand to Fill:

<Button        Text="Get This Working"        HorizontalOptions="Fill"/>

I got this:

enter image description here

And if you want the button fill the Frame and keep the button's text at the start. You need to call the platform code.

Give the button a name:

<Button x:Name="button"       Text="Get This Working"        HorizontalOptions="Fill"/>

And call the platform code in the code behind:

        protected override void OnHandlerChanged()        {            base.OnHandlerChanged();#if WINDOWS            var btn = button.Handler.PlatformView as Microsoft.Maui.Platform.MauiButton;            btn.HorizontalContentAlignment = Microsoft.UI.Xaml.HorizontalAlignment.Left;#elif ANDROID            var btn = button.Handler.PlatformView as Google.Android.Material.Button.MaterialButton;            btn.TextAlignment = Android.Views.TextAlignment.ViewStart;#elif IOS            var btn = button.Handler.PlatformView as UIKit.UIButton;            btn.TitleLabel.TextAlignment = UIKit.UITextAlignment.Left;#endif        }

And I got this:

enter image description here

Finally, the Frame was deprecated in MAUI, you can use the Border instead.


Viewing all articles
Browse latest Browse all 445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>