So I have an application with a long list selector, half the text goes off the screen, so I was trying to pan it when the user flicks the screen. This is the code I have so far...
C#:
private void RouteLLS_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
if (e.DeltaManipulation.Scale.X == 0.0 && e.DeltaManipulation.Scale.Y == 0.0)
{
LongListSelector longListSelector = (LongListSelector)sender;
TranslateTransform transform = (TranslateTransform)longListSelector.RenderTransform;
double x = transform.X + e.DeltaManipulation.Translation.X;
if (x > 0.0)
{
x = 0.0;
}
else if (x < Application.Current.Host.Content.ActualWidth - longListSelector.ActualWidth)
{
x = Application.Current.Host.Content.ActualWidth - longListSelector.ActualWidth;
}
transform.X = x;
}
}
private void RouteLLS_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if (e.IsInertial)
{
LongListSelector longListSelector = (LongListSelector)sender;
TranslateTransform transform = (TranslateTransform)longListSelector.RenderTransform;
double dx = e.FinalVelocities.LinearVelocity.X / 10.0;
double x = transform.X + dx;
if (x > 0.0)
{
x = 0.0;
}
else if (x < Application.Current.Host.Content.ActualWidth - longListSelector.ActualWidth)
{
x = Application.Current.Host.Content.ActualWidth - longListSelector.ActualWidth;
}
panAnimation.To = x;
Pan.Begin();
}
}
And this is the XAML for the animation...
<phone:LongListSelector x:Name="RouteLLS" Grid.Row="3" Background="Transparent" ItemTemplate="{StaticResource routing}" LayoutMode="List"
IsGroupingEnabled="False" ManipulationDelta="RouteLLS_ManipulationDelta" ManipulationCompleted="RouteLLS_ManipulationCompleted">
<phone:LongListSelector.RenderTransform>
<TranslateTransform x:Name="pan"/>
</phone:LongListSelector.RenderTransform>
<phone:LongListSelector.Resources>
<Storyboard x:Name="Pan">
<DoubleAnimation x:Name="panAnimation"
Storyboard.TargetName="pan"
Storyboard.TargetProperty="X"
Duration="0:0:1"
>
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</phone:LongListSelector.Resources>
</phone:LongListSelector>
I'm not receiving an error when I touch the screen or anything so I'm not entirely sure what I'm doing wrong. Unless you're just not allowed to do this kind of thing on a longlistselector? any help appreciated, thanks in advance!
Okay, so I fixed the problem. In the LongListSelector element tag I forgot set a width so there was no "actual width" for it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.