Is it possible? Below if what we've tried so far.
public class ExtendLabel : Label {
public ExtendLabel() {
this.HorizontalOptions = LayoutOptions.FillAndExpand;
}
public static BindableProperty WidthInPercentProperty =
BindableProperty.Create<ExtendLabel, double>(o => o.WindthInPercent, default(double));
public double WindthInPercent
{
get { return (double)GetValue(WidthInPercentProperty); }
set { SetValue(WidthInPercentProperty, value); }
}
protected override void OnSizeAllocated (double width, double height)
{
this.WidthRequest = WindthInPercent * width;
this.InvalidateMeasure ();
}
}
There is a bindable property called WidthInPercent representing a value between 0.0 and 0.1.
In debug it's visible that the width param of the OnSizeAllocated method is indeed the whole width of the label, but this.WidthRequest = WindthInPercent * width does not work.