Windows 8商店应用程序平滑方向改变
本文关键字:平滑 方向 改变 应用程序 Windows | 更新日期: 2023-09-27 18:05:40
我有以下问题:
当我改变我的c#+xaml页面的方向从横向到纵向或反之亦然,在布局被重新计算和重新渲染之前,用户可以在屏幕上看到大的蓝色部分。这些斑点似乎是先前定向状态的残余。
我正在寻找一种方法来隐藏或平滑这个极其粗糙和颠簸的过渡。
我尝试添加一个方向变化处理程序与ProgressRing覆盖它1秒,但它没有帮助-处理程序在蓝色点后执行。这是我的动画StoryBoard的代码
<!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
<VisualState x:Name="FullScreenPortrait">
<Storyboard>
<!-- Change the back button and the logo -->
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerLogoImage" Storyboard.TargetProperty="Width">
<DiscreteObjectKeyFrame KeyTime="0" Value="430"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerLogoImage" Storyboard.TargetProperty="Height">
<DiscreteObjectKeyFrame KeyTime="0" Value="49"/>
</ObjectAnimationUsingKeyFrames>
<!--Change section title and navButtons to be in two rows, by moving navButtons to the second row, first column-->
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="navButtons" Storyboard.TargetProperty="(Grid.Row)">
<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="navButtons" Storyboard.TargetProperty="(Grid.Column)">
<DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="navButtons" Storyboard.TargetProperty="(Grid.ColumnSpan)">
<DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="navButtons" Storyboard.TargetProperty="Margin">
<DiscreteObjectKeyFrame KeyTime="0" Value="0,15,0,0"/>
</ObjectAnimationUsingKeyFrames>
<!--Change the grid-->
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemPortraitGridView" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
任何帮助都是感激的,谢谢!
编辑:我用下面的方法(在同事的帮助下)解决了这个问题:
/// <summary>
/// On Orientation change collapse all views, and make visible only the views for the particular new orientation
/// Also change the font size for portrait mode
/// </summary>
/// <param name="sender"></param>
private async void OnOrientationChanged(object sender)
{
headerGrid.Visibility = Visibility.Collapsed;
itemGridView.Visibility = Visibility.Collapsed;
itemPortraitGridView.Visibility = Visibility.Collapsed;
itemListView.Visibility = Visibility.Collapsed;
//Make the loading spinner temporarily visible and stop it in the StoryBoard animation for every orientation separately
LoadingView.Visibility = Visibility.Visible;
//Change the font size
if (ScreenHelper.IsInPortraitMode())
{
_viewModel.FontSizeMethod = _viewModel.GetPortraitFontSize;
}
else
{
//change font size method back
_viewModel.FontSizeMethod = _viewModel.GetLandscapeFontSize;
}
// Change visibility back to normal in case the xaml approach failed.
await Task.Delay(1000);
if (ScreenHelper.IsInPortraitMode())
itemPortraitGridView.Visibility = Windows.UI.Xaml.Visibility.Visible;
else if (ApplicationView.Value == ApplicationViewState.Snapped)
itemListView.Visibility = Windows.UI.Xaml.Visibility.Visible;
else
itemGridView.Visibility = Windows.UI.Xaml.Visibility.Visible;
headerGrid.Visibility = Visibility.Visible;
LoadingView.Visibility = Visibility.Collapsed;
}
我知道你把这个标记完成了,但是因为我不能发表评论,所以我不得不在这里问一下。你可以用松弛法来解这个吗?