<Grid BackgroundColor="Blue">
<border:SfBorder Padding="0" BorderWidth="0" CornerRadius="10,10,0,0">
<Grid BackgroundColor="Red">
<Grid.GestureRecognizers>
<PanGestureRecognizer PanUpdated="PanGestureRecognizer_PanUpdated"/>
</Grid.GestureRecognizers>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid x:Name="_headerView" BackgroundColor="Blue" HeightRequest="200">
<Label FontSize="Large" HorizontalOptions="Center" Text="HEADER" TextColor="White" VerticalOptions="Center" />
</Grid>
<listviewsample:SfListViewEx x:Name="_listView" Grid.Row="1" Margin="0,20,0,20" AllowSwiping="True" AutoFitMode="Height" DragStartMode="OnHold, OnDragIndicator" ItemDragging="SfListView_ItemDragging" ItemSpacing="0" InputTransparent="{Binding CanPassTouch}" ItemsSource="{Binding ItemCollection}" RightSwipeCommand="{Binding SwipeRightCommand}" SwipeOffset="200">
... |
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;
}
} |