Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin表单-滚动查看如何检查是否滚动到底部_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin表单-滚动查看如何检查是否滚动到底部

Xamarin表单-滚动查看如何检查是否滚动到底部,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我想检查它是否已滚动到底部,但代码结果令我不满意 CurrentHeight(2716.38095238095)=内容高度(2717.2380952381) 虽然他们很接近但不一样,为什么 private void scrollView_Scrolled(object sender, ScrolledEventArgs e) { OnScroll(e.ScrollY); var CurrentHeight = scrollView.Bounds.Height + scrollVi

我想检查它是否已滚动到底部,但代码结果令我不满意
CurrentHeight(2716.38095238095)=内容高度(2717.2380952381)

虽然他们很接近但不一样,为什么

private void scrollView_Scrolled(object sender, ScrolledEventArgs e) {
    OnScroll(e.ScrollY);
    var CurrentHeight = scrollView.Bounds.Height + scrollView.ScrollY + scrollView.Padding.VerticalThickness;
    var ContentHeight = scrollView.ContentSize.Height;

    Debug.WriteLine("计算当前高度:" + CurrentHeight + "|" + "内容区域总高度:" + ContentHeight + "|" + "滚动条Y:" + e.ScrollY + "|" + "当前可视区域高度:" + scrollView.Bounds.Height);

    if (scrollView.Height == e.ScrollY) {

    }
    OnScrollEnd();
}

这一个非常适合我,两个值在滚动的末尾都匹配:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="BookApp.Views.ChapterPageDetail"
             Title="{Binding Name}">


    <ScrollView x:Name="scrollView" Padding="0" Scrolled="scrollView_Scrolled" >
        <StackLayout x:Name="stackLayout" Padding="10">
            <Label Text="{Binding Content}" TextColor="#070707"/>
            <Button Text="Next chapter" Clicked="Button_Clicked"></Button>
            <StackLayout.GestureRecognizers>
                <SwipeGestureRecognizer Direction="Left" Swiped="OnSwipedLeft"/>
                <SwipeGestureRecognizer Direction="Right" Swiped="OnSwipedRight"/>
            </StackLayout.GestureRecognizers>
        </StackLayout>
    </ScrollView>
</ContentPage>
也不确定以下内容是否会影响您,但请注意,在iOS上存在某种错误,ScrollView有时会将其位置设置为负值,这可以通过中的渲染器修复

受保护的覆盖无效OnElementChanged(VisualElementChangedEventArgs e)

设置一个可爱的
((滚动视图)e.NewElement)

这将禁用反弹功能。

这是否回答了您的问题?我不知道你是否必须像我一样出口。[0:]滚动到位置3152.7619047619,最大值:3152.47619047619当我滚动到末尾时,这两个值非常相似,但不相等。在下面发布您的页面Xaml检查如果您的问题来自stacklayout padding=10,只需将边距添加到其子项即可
 private void ScrollView_OnScrolled(object sender, ScrolledEventArgs e)
        {
            var scrollView = sender as ScrollView;
            try
            {
                var contentSize = scrollView.ContentSize.Height;
                var contentSizeCheck = ((View) scrollView.Children[0]).Height; //for fun

                var maxPos = contentSize - scrollView.Height;

                Debug.WriteLine($"Scrolled to pos {e.ScrollY}, max: {maxPos}");
            }
            catch
            {

            }
        }