Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Set WidthRequested in percentage

$
0
0

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.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>