locked
Scrollview inside Frame doesn't give the actual frame height RRS feed

  • Question

  • User96727 posted

    Hi,

    I need to get a Frame height during runtime but since I added a scrollview inside Frame I don't get actual frame height. If I remove scrollview I get different height than when it is inside Frame.

    <StackLayout Padding="5" x:Name="mainLayout"> **<Frame** Padding="10" Style="{x:StaticResource BaseFrameStyle}"> ** <ScrollView>** <Grid Style="{x:StaticResource ZeroSpacingGridStyle}"> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition>

    What is the best approach to get the actual frame height when we have scrollview inside it?

    Also tried adding VerticalOptions for scrollview to FillAndExpand even that didn't help

    Tuesday, November 3, 2020 7:29 AM

Answers

  • User382871 posted

    Do you mean that there are too many views in scrollView that part of the content has been hidden? Because ScolllView is scrollable, the scrollView's height is not the same as it's content in this case.

    To get the size of the frame, try getting the height of the scrollView's content instead. If you set Padding for the layout, then add the padding value to calculate to get the height of the frame.

    Check the code: <StackLayout Padding="5" x:Name="mainLayout"> <Button Clicked="Button_Clicked"/> <Frame x:Name="frame" Padding="10" BackgroundColor="LightPink" ...> <ScrollView> <Grid x:Name="_content"> ... <StackLayout > </ScrollView> </Frame> </StackLayout> Get the frame's height in the click event. ``` private void Button_Clicked(object sender, EventArgs e) { var value = _content.Height;

    var frame_height = frame.Padding.Bottom + frame.Padding.Top + value;
    

    } ```

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 4, 2020 8:02 AM

All replies

  • User382871 posted

    How did you get the frame's height? I tested you code to get the height of the Frame, it works fine. When adding content to the grid, the height of the frame will increase.

    Check the code: <StackLayout Padding="5" x:Name="mainLayout"> <Frame x:Name="frame" Padding="10" ...> <ScrollView> ... </ScrollView> </Frame> <Button Clicked="Button_Clicked"/> </StackLayout> Button's click event private void Button_Clicked(object sender, EventArgs e) { var value = frame.Height; }

    Tuesday, November 3, 2020 10:29 AM
  • User96727 posted

    Hi @Jarvan ,

    Yes we get the Height but have you tried by removing the scrollview in the frame for the same content?

    You will get a different Height when you remove the scrollview, I am looking for that Height actually.

    Wednesday, November 4, 2020 4:36 AM
  • User382871 posted

    Do you mean that there are too many views in scrollView that part of the content has been hidden? Because ScolllView is scrollable, the scrollView's height is not the same as it's content in this case.

    To get the size of the frame, try getting the height of the scrollView's content instead. If you set Padding for the layout, then add the padding value to calculate to get the height of the frame.

    Check the code: <StackLayout Padding="5" x:Name="mainLayout"> <Button Clicked="Button_Clicked"/> <Frame x:Name="frame" Padding="10" BackgroundColor="LightPink" ...> <ScrollView> <Grid x:Name="_content"> ... <StackLayout > </ScrollView> </Frame> </StackLayout> Get the frame's height in the click event. ``` private void Button_Clicked(object sender, EventArgs e) { var value = _content.Height;

    var frame_height = frame.Padding.Bottom + frame.Padding.Top + value;
    

    } ```

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 4, 2020 8:02 AM
  • User96727 posted

    @Jarvan , that works!. Thank you for the suggestion.

    Wednesday, November 4, 2020 12:54 PM