我正在尝试使用此代码获取解锁手机效果 Mimicking WP7 Unlock Page Animation
但我真的不知道如何让它发挥作用。我没有使用Storyboard
的经验而且我在gridTranslate
收到错误,因为我没有对它进行定义。我不知道如果我正确地放置代码。有人可以帮助我吗
我的xaml代码是
<Grid Grid.Row="1" x:Name="LockScreenGrid" Visibility="{Binding LockScreenGridVisibility}" ManipulationDelta="lock_ManipulationDelta" ManipulationCompleted="lock_ManipulationCompleted" >
<Grid.RenderTransform>
<TranslateTransform x:Name="GridTranslate" />
</Grid.RenderTransform>
<Grid.Resources>
<Storyboard x:Name="LockScreenSlideAnimation">
<DoubleAnimation Duration="0:0:1" To="-768"
Storyboard.TargetProperty="
(UIElement.RenderTransform).
(CompositeTransform.TranslateY)"
Storyboard.TargetName="LockScreenGrid" d:IsOptimized="True"/>
</Storyboard>
<Storyboard x:Name="CoastGrid" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="LockScreenGrid" Storyboard.TargetProperty="(UIElement.RenderTransform)
.(CompositeTransform.TranslateY)">
<EasingDoubleKeyFrame x:Name="coastY"
KeyTime="00:00:01" Value="0">
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
</Grid>
我的.cs代码是
public SlideTest()
{
InitializeComponent();
}
private void lock_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if (this.gridTranslate.TranslateY < 0.0)
{
IEasingFunction function;
this.CoastGrid.Stop();
this.gridTranslate.TranslateY = e.TotalManipulation.Translation.Y;
if ((e.IsInertial) && (e.FinalVelocities.LinearVelocity.Y < -1500) ||
(this.gridTranslate.TranslateY < (base.ActualHeight / -2.0)))
{
this.coastY.Value = (-1.0 * this.LockScreenGrid.ActualHeight);
function = new CircleEase();
((CircleEase)function).Ease(1.0);
}
else
{
this.coastY.Value = 0.0;
function = new BounceEase();
((BounceEase)function).Ease(0);
((BounceEase)function).Ease(2);
((BounceEase)function).Ease(5.0);
}
this.coastY.EasingFunction = function;
this.CoastGrid.Begin();
}
}
private void lock_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
e.Handled = true;
this.gridTranslate.TranslateY = (this.gridTranslate.TranslateY +
e.DeltaManipulation.Translation.Y);
if (this.gridTranslate.TranslateY > 0.0)
{
this.gridTranslate.TranslateY = 0.0;
}
}
这只是我从源代码中获取的代码的复制/粘贴。我不知道如果我需要一些参考,或者我必须定义gridTranslate
答案 0 :(得分:0)
您的XAML有一个名为GridTranslate的元素,而您的代码使用gridTranslate - 请注意不同的外壳。