How to get a label's Height

Hi, I have a none static label on my project that gets updated with different values. I was wondering if there is any way of getting the height and width of the label after the text was updated?

I have used various methods including label.Bounds but it always returns a -1. I have also put the label inside a frame thinking it would make a difference but it returns -1

Can anyone help me with this?

Thank you,
Jason

Posts

  • DavidDancyDavidDancy AUMember ✭✭✭✭

    label.SizeChanged += (object sender, EventArgs e) { /* label.Width and label.Height should have good values here */ }

  • JasonJavaJasonJava USMember

    Hi David,
    Thank you, that was exactly what I was looking for!!

  • GaneshJGaneshJ USMember

    Hello,

    This is still not working for me.

            var MyLabel = new Label 
            { 
                Text = "Get The Height of this label",
                FontSize = 11,
                FontFamily = Device.OnPlatform(
                    "Lato-Light",
                    null,
                    null
                ) // set only for iOS
    
            };
            double height = 0;
            MyLabel.SizeChanged += (object sender, EventArgs e) => { 
        /* label.Width and label.Height should have good values here */ 
                height = MyLabel.Height;
            };
    

    could you please help me as to what is wrong here?

Sign In or Register to comment.