我很困惑为什么我的应用程序关闭,我添加了 PointerDownThemeAnimation 并且它工作正常但只有一次,当我尝试再次单击它时应用程序停止。为什么?
这是我的代码:
private void staryrynek1(object sender, PointerRoutedEventArgs e)
{
pointerDownStoryboard.Begin();
}
private void staryrynek(object sender, PointerRoutedEventArgs e)
{
pointerUpStoryboard.Begin();
this.Frame.Navigate(typeof(StaryRynek));
}
和
<Grid x:Name="staryrynek_grid" Margin="10,92,10,0" VerticalAlignment="Top" PointerPressed="staryrynek1" PointerReleased="staryrynek">
<Grid.Resources>
<Storyboard x:Name="pointerDownStoryboard">
<PointerDownThemeAnimation TargetName="staryrynek_grid" />
</Storyboard>
<Storyboard x:Name="pointerUpStoryboard">
<PointerUpThemeAnimation TargetName="staryrynek_grid" />
</Storyboard>
</Grid.Resources>
<Grid.Background>
<SolidColorBrush Color="Black" Opacity="0.495"/>
</Grid.Background>
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="380" FontSize="29.333" Text="Stary Rynek"/>
</Grid>
最佳答案
我想你发现了一个真正的错误。这是解决方法。
XAML
<Grid>
<Grid.Resources>
<Storyboard x:Name="PointerDownStory">
<PointerDownThemeAnimation TargetName="MyRectangle" />
</Storyboard>
<Storyboard x:Name="PointerUpStory">
<PointerUpThemeAnimation TargetName="MyRectangle" />
</Storyboard>
<Style TargetType="Rectangle">
<Setter Property="Width" Value="300" />
<Setter Property="Height" Value="200" />
<Setter Property="Fill" Value="White" />
</Style>
</Grid.Resources>
<Rectangle x:Name="MyRectangle"
PointerPressed="Grid_PointerPressed"
PointerReleased="Grid_PointerReleased" />
</Grid>
代码隐藏
private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
{
this.MyRectangle.Projection = new PlaneProjection();
PointerDownStory.Begin();
}
private void Grid_PointerReleased(object sender, PointerRoutedEventArgs e)
{
PointerUpStory.Begin();
}
这是您应该注意到的
this.MyRectangle.Projection = new PlaneProjection();
行。这是对原始代码的唯一真正更改。似乎 PointerUpThemeAnimation
无意中破坏了 PlaneProjection
。如果 PointerDownThemeAnimation
会重新创建它,那就没问题了。祝你好运!
关于c# - PointerDownThemeAnimation 应用程序停止 WP8,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24023458/