Reputation: 427
I am using a translateX manipulation in my app. but when I want to use it in a scrollviewer, The scrollviewer stops working and doesn't scroll(I need the vertical rail). What to do to fix it. MyXAML code:
<ScrollViewer>
<Grid x:Name="MainGrid" Background="{ThemeResource AppBackgroundColor}"
ManipulationMode="TranslateX" ManipulationDelta="MainGrid_ManipulationDelta" ManipulationCompleted="MainGrid_ManipulationCompleted"
ManipulationStarted="MainGrid_ManipulationStarted"
>
<ContentControl Content="{x:Bind TheGrid,Mode=OneWay}"/>
<Grid.RenderTransform >
<TranslateTransform x:Name="myScaleTransform" />
</Grid.RenderTransform>
</Grid>
</ScrollViewer>
And my C# codebehind:
#region Manipulations
private void MainGrid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (myScaleTransform.X >= 60 && e.Delta.Translation.X > 1)
{
myScaleTransform.X = 60;
return;
}
if (myScaleTransform.X <= -180 && e.Delta.Translation.X < 1)
{
myScaleTransform.X = -180;
return;
}
myScaleTransform.X += e.Delta.Translation.X;
lastPostition.X += e.Delta.Translation.X;
}
private void MainGrid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
if (myScaleTransform.X <= -170 ) return;
urStoryboard.Begin();
}
private void MainGrid_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
startpoint = e.Position;
lastPostition = e.Position;
}
}
#endregion
Upvotes: 1
Views: 1139
Reputation: 78
Unfortunately there is no good solution if the ScrollViewer
needs both scrolling and gestures. If you want to handle user's gestures you have to disable DirectManipulation
and this disables scrolling as well.
There's an article talk about this problem, you should read this to understand more.
Upvotes: 1