Maui android scrolltoasync(x, y, false) x y values issue

Haviv Elbsz 2,071 Reputation points
2023-01-17T07:37:49.3466667+00:00

Hello all. I have a label text with many lines of text and I want to jump to some line by using scrolltoasync method. if I use scrolltoasync(0, 12, false) the jump is hardly one line. how I can or what is the value definition. mainly if I want to jump to line 12 which value I should use. or what calculations I need to do. Thank you very much

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,336 Reputation points Microsoft Vendor
    2023-01-19T05:04:09.23+00:00

    Hello,

    how I can or what is the value definition. mainly if I want to jump to line 12 which value I should use

    Because Label do not have method to get the lines, we can do this by using Label's fontSize and add default padding (10) to get the text line height, then multiply by 12 like following code.

    MyScrollVIew.ScrollToAsync(0, (MyLabel.FontSize+10)*12, false);
    

    My XAML layout like following.

    <ScrollView x:Name="MyScrollVIew" HeightRequest="100">
                <Label x:Name="MyLabel"  FontSize="Title"></Label>
    </ScrollView>
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful