Forum Xamarin.Forms

What are Scale, ScaleX and ScaleY supposed to do?

JohnHardmanJohnHardman GBUniversity admin

I apply ScaleY to a ProgressBar to make it taller. However, I find that it then goes behind the Views that I would expect to be above it and below it, rather than doing a layout cycle that results in Views being re-positioned to prevent overlap.

The documentation for ScaleY simply says "Gets or sets a scale value to apply to the Y direction", which I would interpret as the VisualElement is made taller and that everything adjusts as per VerticalLayout options etc.
See https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.visualelement.scaley?view=xamarin-forms

Am I misinterpreting what the different scaling properties are intended to do? If so, how should I scale a VisualElement such that the page it is on performs a layout cycle to simply make the VisualElement larger and move other Views to prevent overlapping elements?

cc @DavidBritch

Best Answer

  • ColeXColeX Member, Xamarin Team Xamurai
    edited February 22 Accepted Answer

    I reproduced the issue , the ProgressBar goes behind if changes its ScaleY .

    Even I use layout.RaiseChild(); method the problem persists.

    As a workaround ,I add a class extension method to VisualElement.

        public static class MyExtensions
        {
            public static void _Scale(this VisualElement element ,double ScaleX =1 ,double ScaleY=1)
            {
                element.WidthRequest = element.Width * ScaleX;
                element.HeightRequest = element.Height * ScaleY;
            }
        }
    
    //usage
    control._Scale(2,3);
    

    In this way the control does not overlap the other view .


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited February 22 Accepted Answer

    I reproduced the issue , the ProgressBar goes behind if changes its ScaleY .

    Even I use layout.RaiseChild(); method the problem persists.

    As a workaround ,I add a class extension method to VisualElement.

        public static class MyExtensions
        {
            public static void _Scale(this VisualElement element ,double ScaleX =1 ,double ScaleY=1)
            {
                element.WidthRequest = element.Width * ScaleX;
                element.HeightRequest = element.Height * ScaleY;
            }
        }
    
    //usage
    control._Scale(2,3);
    

    In this way the control does not overlap the other view .


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • JohnHardmanJohnHardman GBUniversity admin

    @ColeX said:
    I reproduced the issue , the ProgressBar goes behind if changes its ScaleY .

    Thanks @ColeX . I'll log an issue in GitHub for this.

    @ColeX said:
    As a workaround ,I add a class extension method to VisualElement.

    That workaround relies on one layout cycle having been done already, and relies on only being called once. However, I can make use of it until the underlying issue is resolved. Thanks

Sign In or Register to comment.