How to format a Label using StringFormat in Xamarin Forms

-2

I'm creating a solution where I should display an integer in a <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 have an 8-digit mask. How do I apply the mask to the StringFormat property so that the displayed value is 00000010 ?

    
asked by anonymous 09.10.2018 / 16:42

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>
    
10.10.2018 / 14:39