Jimmy
Jimmy

Reputation: 1349

Xamarin binding, Label only displaying 1 character

I have a Label that is binding to a property, so that when that property is updated, the Label is updated. But, for example, if the property has the value 500, the label only displays "5", instead of "500". If I remove the binding and hard code label = "500", the entire string show up. What's the deal? My code looks something like this ...

var myLabel = new Label
{
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center,
    FontSize = 30,
    TextColor = Color.Red
};

myLabel.SetBinding(Label.TextProperty, new Binding("SomeProperty", source:this);

// where SomeProperty is a property that gets an integer value dynamically

so, running code similar to that, the label is output as "5" (assuming SomeProperty = 500, if SomeProperty is 432354, the label shows only "4"). However, if instead of setting the binding I do

myLabel = "500";

then, the label shows "500".

Why is the binding cutting off the string???

Upvotes: 0

Views: 470

Answers (1)

Ivan Bukashkin
Ivan Bukashkin

Reputation: 694

Its is not the binding cutting off your string, it is size of Label not changing dynamically for your content. Set it directly by setting WidthRequest or MinimumWidthRequest properties

Upvotes: 3

Related Questions