XamarinForms粘性头

问题描述 投票:0回答:1

我在寻找一个解决方案,在这里代表了我的设计师的gif。在这里输入链接描述

基本上,我需要一个列表,有一个头,或者有另一个视图(grid,或者stacklayout),在滚动时,我需要捕捉事件(向下滚动,向上滚动),并且用该头移动列表。在滚动时,我需要捕捉事件(向下滚动,向上滚动),并与该头移动列表。https:/www.syncfusion.comdownloadssupportdirecttracgeneralzeAnimateHeaderOnScroll1119606059

xamarin xamarin.forms syncfusion
1个回答
0
投票

你可以通过处理Scrolled事件来实现你的要求,如下所示。

public MainPage() 
{ 
            InitializeComponent(); 
            container = _listView.GetVisualContainer(); 
            _scrollView = _listView.GetScrollView(); 
            _scrollView.Scrolled += ScrollView_Scrolled; 
} 

private void ScrollView_Scrolled(object sender, ScrolledEventArgs e) 
{ 
    scrollOffet = (double)container.GetType().GetRuntimeProperties().First(p => p.Name == "ScrollOffset").GetValue(container); 

    if (e.ScrollY == 0) 
        (BindingContext as MainViewModel).CanPassTouch = true; 
} 

private void PanGestureRecognizer_PanUpdated(object sender, PanUpdatedEventArgs e) 
{ 
    if(e.StatusType == GestureStatus.Running) 
    { 
        var y = e.TotalY; 

        //Up scroll 
        if (y < 0) 
        { 
            if (!_originalHeaderHeight.HasValue) 
            { 
                _originalHeaderHeight = _headerView.Height; 
            } 
            var newHeight = _originalHeaderHeight.Value + y; 
            _headerView.HeightRequest = newHeight > MIN_HEADER_HEIGHT ? newHeight : MIN_HEADER_HEIGHT; 
        } 
        //Down scroll 
        else 
        { 
            if (!_originalHeaderHeight.HasValue) 
            { 
                _originalHeaderHeight = _headerView.Height; 
            } 
            var newHeight = _originalHeaderHeight.Value + y; 
            _headerView.HeightRequest = newHeight < MAX_HEADER_HEIGHT ? newHeight : MAX_HEADER_HEIGHT; 
        } 

        //Enable InputTransparent for SfListView, to enable the ListView scrolling 
        //after reaching the Header min/max heights based on scrolling. 
        if (_headerView.HeightRequest == MIN_HEADER_HEIGHT && y < 0) 
            (BindingContext as MainViewModel).CanPassTouch = false; 
        if (_headerView.HeightRequest == MAX_HEADER_HEIGHT && scrollOffet > 0) 
            (BindingContext as MainViewModel).CanPassTouch = false; 
    } 
} 

样品

© www.soinside.com 2019 - 2024. All rights reserved.