31

In my xamarin forms project button text are always show in uppercase format.
But I am providing upper and lower case letters in xaml. When I build the solution all the letters are changed to uppercase.

Cfun
  • 8,442
  • 4
  • 30
  • 62
Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105

5 Answers5

51

I'm guessing you see this on Android as it is the default for button text and has been since Lollipop.

To change this behavior add the following to your styles.xml file which can be found in the Android project under the Resources then values folders

<item name="android:textAllCaps">false</item>
Steve Chadbourne
  • 6,873
  • 3
  • 54
  • 82
20

An alternative is to simply use TextTransform property:

<Button Text="Click Me" TextTransform="None"/>

Or in a style definition:

<Style TargetType="Button" x:Key="NoDefaultCapsButton">
     <Setter Property="TextTransform" Value="None"/>
</Style>

<Button Text="Click Me" Style="{x:StaticResource NoDefaultCapsButton}"/>

Important Note

Be sure you are using Xamarin.Forms NuGet package 4.8.0.1534 or above, if TextTransform is not showing for you than clean and rebuild your solution.

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • Where are you seeing this option? I am using Visual Studio Pro 2019 with a new Xamarin.Forms project but there is no `TextTransform` option in either the Properties window of my `Button` or while trying to use a `` in `App.xaml` > `ApplicationResources` > ` – Danny Beckett Oct 30 '20 at 10:20
  • @DannyBeckett https://i.stack.imgur.com/utqJt.png Which platform are you targeting? Maybe you are using an old version of Xamarin.Forms (I think it was introduced in 4.8). – Cfun Oct 30 '20 at 10:31
  • My About page of VS is showing .NET as on v4.8.04084. Xamarin is on v16.7.000.463, Xamarin Designer is on v16.7.0.495, Xamarin Templates is on v16.7.85, Xamarin.Android SDK is on v11.0.2.0. My Shared project properties has the Target Framework as .NET *Standard* 2.0. The Android project properties has the Target Framework as Android 9.0 (Pie). The Android Manifest has the Minimum Android Version as Android 4.1 (API Level 16 - Jelly Bean). It has the Target Android Version as Android 9.0 (API Level 28 - Pie). Thanks for your help! – Danny Beckett Oct 30 '20 at 10:38
  • @DannyBeckett When I updated Xamarin.Forms it complains with some warning in order to set the Target Framework to `Android Q 10.0`. This is the only difference between our used versions. – Cfun Oct 30 '20 at 10:43
  • I've changed my Target Framework in both places to Android 10.0 (API Level 29 - Q) but still no joy unfortunately! Is your Minimum Android Version Android 4.1 (API Level 16 - Jelly Bean)? Thanks for trying. – Danny Beckett Oct 30 '20 at 10:50
  • @DannyBeckett no it is (Android 8.0 API Level 26). Which Xamarin.Forms NuGet package version are you using? – Cfun Oct 30 '20 at 10:57
  • 1
    My Xamarin.Forms NuGet package was on 4.6.0.1141. I've updated it to 4.8.0.1560 and the TextTransform property is now available. I didn't need to modify the Minimum Android Version. Thank you once again :) – Danny Beckett Oct 30 '20 at 11:12
  • Happy to help :) – Cfun Nov 13 '20 at 16:34
12

The accepted answer assumes the user (even a newbie) to know which style the above code goes in. Even the comments below the accepted answer remain unanswered... I wonder why...

I just started learning Android Xamarin programming and I spent some good 20 mins to figure it out. For any users, specially newbies, see this example.

In your Android project, go to Resources > values > styles.xml and add:

<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:textAppearanceButton">@style/mybutton.text</item>
</style>

<style name="mybutton.text" parent="Base.TextAppearance.AppCompat.Button">
    <item name="android:textAllCaps">false</item>
</style>

Screenshot:

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • I tried this but it has no effect. All I had to do was copy your text into the myapp.Android/Resources/values/styles.xml right ? Do I need to do some action before this kicks in ? – GuidoG Dec 29 '21 at 15:02
  • @GuidoG: I stopped working on these long time ago. You may want to see other answers which were posted after mine and also cover latest versions? – Siddharth Rout Dec 29 '21 at 18:28
7

Recently I had the same issue even though I was using textAllCaps false in my styles. It seems it doesn't work with prerlease version 4.8.0.1238-pre3 of Xamarin.Forms (latest available at the time of posting this). It does work with version 4.7.0.1239 of Xamarin.Forms.

Marius Rusu
  • 93
  • 1
  • 6
0

Solutions for this issue that works for me in android and iOS for material to avoid automatic UpperCase conversion when Visual is set to "Material".

Xamarin.Forms.Android:

<style name="MainTheme" parent="MainTheme.Base">
    <item name="android:textAllCaps">false</item>
</style>

Xamarin.Forms.iOS:

[assembly: ExportRenderer(typeof(Button), typeof(ButtonRendererEx), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace GettingStarted.iOS
{
    public class ButtonRendererEx : MaterialButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.UppercaseTitle = false;
            }
        }
    }
}
cruzier
  • 358
  • 2
  • 14
  • Using a `CustomRenderer` for this is an overkill I think, for Android part of the answer it is the same as [Steve's answer](https://stackoverflow.com/a/47545821/5228202) – Cfun Nov 13 '20 at 16:33