Dmitry Ponomarenko
Dmitry Ponomarenko

Reputation: 156

Handling of ManipulationDelta event breaks parent ScrollViewer

I want to implement animation like this:

Demo

So I decided to use FlipView as main container and grid with two rows as data template. Grid will handle ManipulationDelta event to decrease height of the first part of text so the second part becomes be visible. When text height reaches minimum value we must route event to parent ScrollViewer so it can flip to the next item.

private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        if (CanDecreaseLine(e))
        {
            //Decrease first line height...
            e.Handled = true;
        }
    }

But I faced the problem that when I try to handle ManipulationDelta on child (Grid) side the FlipView stops working. No matter whether we set Handled property or not

Here is simplified xaml:

<FlipView>
        <FlipView.ItemTemplate>
            <DataTemplate>
                <Grid Background="Transparent" 
                  ManipulationMode="TranslateY, TranslateInertia"
                  ManipulationDelta="OnManipulationDelta">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Text="FirstLine"/>
                    <TextBlock Grid.Row="1" Text="SecondLine"/>
                </Grid>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>

The ScrollViewer stops working because of ManipulationMode="TranslateY, TranslateInertia", but without it Grid won't receive manipulation events that I need to change size of Grid rows to achieve animation.

Is it possible to handle manipulation events on child of ScrollViewer or is there any other way to achieve this animation?

Upvotes: 1

Views: 675

Answers (1)

Jon G St&#248;dle
Jon G St&#248;dle

Reputation: 3904

You could try to subscribe to the ManipulationDelta event when the FlipView changes SelectedItem. Then handle it internally in the Grid as you need. Then when you detect the user scrolling further and you should stop handling the event in the Grid, unsubscribe to the event and let the FlipView handle it as normal.

Haven't tested this, so not sure if it'll work.

Also, you'll probably have to do some digging through the visual tree to fetch the right Grid to sub to the event. Or use a UserControl in the DataTemplate which has a property (that can be bound to) that can toggle subscription for the ManipulationDelta event.

Upvotes: 2

Related Questions