具体思路是:
void ContentFrame_Navigating(object sender, NavigatingCancelEventArgs e) { LastFrameContent = new WriteableBitmap(ContentFrame, null); }并在 ContentFrame_Navigated(object sender, NavigationEventArgs e)的方法里赋值给模板页(此时我们叫模板页)
private void ContentFrame_Navigated(object sender, NavigationEventArgs e) { FrameMaskImage.Source = LastFrameContent; FrameStory.Begin(); }
3. 对第二步骤中的图片做从显示到隐藏的动画。
4.对Frame控件做从无到有的动画效果,合起来就是翻页效果了。
具体XMAL文件代码:
<Grid Name="FrameParentPanel" Margin="26,0,26,0" Grid.Row="2"> <Grid.Projection> <PlaneProjection ></PlaneProjection> </Grid.Projection> <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed"> <navigation:Frame.UriMapper> <uriMapper:UriMapper> <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/> <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/> </uriMapper:UriMapper> </navigation:Frame.UriMapper> </navigation:Frame> <!--遮盖层--> <Image Name="FrameMaskImage" VerticalAlignment="Top"></Image> </Grid>具提.cs代码:
public partial class MainPage : UserControl { private Storyboard FrameStory { get; set; } private WriteableBitmap LastFrameContent { get; set; } private const int RotateLag = 300; private const int RotateTimeStep = 50; private const int RotateAngleStep = 15; public MainPage() { InitializeComponent(); this.ContentFrame.Navigating += new NavigatingCancelEventHandler(ContentFrame_Navigating); InitFrameStory(); } void ContentFrame_Navigating(object sender, NavigatingCancelEventArgs e) { LastFrameContent = new WriteableBitmap(ContentFrame, null); } void InitFrameStory() { //旋转动画 var pageRotateAnimation = new DoubleAnimationUsingKeyFrames(); for (var i = 0; i <= 12; i++) { pageRotateAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame() { Value = RotateAngleStep * (i < 6 ? i : (i - 12)), KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(RotateLag + RotateTimeStep * i)) }); } //遮盖层动画 var maskAnimation = new ObjectAnimationUsingKeyFrames(); maskAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame() { Value = Visibility.Visible, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)) }); maskAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame() { Value = Visibility.Collapsed, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(RotateLag + RotateTimeStep * 6)) }); //frame控件动画 var frameAnimation = new DoubleAnimationUsingKeyFrames(); frameAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame() { Value = 0.0, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)) }); frameAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame() { Value = 1.0, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(RotateLag + RotateTimeStep * 6)) }); FrameStory = new Storyboard(); FrameStory.Children.Add(pageRotateAnimation); FrameStory.Children.Add(maskAnimation); FrameStory.Children.Add(frameAnimation); Storyboard.SetTarget(pageRotateAnimation, FrameParentPanel.Projection); Storyboard.SetTarget(maskAnimation, FrameMaskImage); Storyboard.SetTarget(frameAnimation, ContentFrame); Storyboard.SetTargetProperty(pageRotateAnimation, new PropertyPath(PlaneProjection.RotationYProperty)); Storyboard.SetTargetProperty(maskAnimation, new PropertyPath(VisibilityProperty)); Storyboard.SetTargetProperty(frameAnimation, new PropertyPath(OpacityProperty)); } // After the Frame navigates, ensure the HyperlinkButton representing the current page is selected private void ContentFrame_Navigated(object sender, NavigationEventArgs e) { FrameMaskImage.Source = LastFrameContent; FrameStory.Begin(); foreach (UIElement child in LinksStackPanel.Children) { HyperlinkButton hb = child as HyperlinkButton; if (hb != null && hb.NavigateUri != null) { if (hb.NavigateUri.ToString().Equals(e.Uri.ToString())) { VisualStateManager.GoToState(hb, "ActiveLink", true); } else { VisualStateManager.GoToState(hb, "InactiveLink", true); } } } } // If an error occurs during navigation, show an error window private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) { e.Handled = true; ChildWindow errorWin = new ErrorWindow(e.Uri); errorWin.Show(); } }