具体思路是:
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(); }
4.对Frame控件做从无到有的动画效果,合起来就是翻页效果了。
<Grid Name="FrameParentPanel" Margin="26,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,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(); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。