How to format a label using Stringformat in Xamarin Forms

Asked

Viewed 602 times

-2

I am creating a solution where I must display a whole in one <Label />. To do this I’m using the code below:

public partial class Home : ContentPage {

    public Home() {
        InitializeComponent();
        BindingContext = this;
        Mockup();
    }

    private int Foo { get; set; }

    private void Mockup() {
        Foo = 10;
    }

}

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 
  xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  x:Class="Test.Home">
  <ContentPage.Content>
    <Label Text="{Binding Foo, Mode=TwoWay } />
  </ContentPage.Content>
</ContentPage>

I need my text to always be with an 8 digit mask. How should I apply the mask to the property StringFormat for the displayed value to be 00000010?

1 answer

1


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 
  xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  x:Class="Test.Home">
  <ContentPage.Content>
    <Label Text="{Binding Foo, Mode=TwoWay, StringFormat='{0,8:00000000}'}" />
  </ContentPage.Content>
</ContentPage>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.