具体思路是:
利用 <PlaneProjection ></PlaneProjection> 对Frame做一个旋转动画。@H_404_12@ 在ContentFrame_Navigating 方法里,记录此时的导航页的图片。@H_404_12@
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,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(); } }总结
以上是内存溢出为你收集整理的利用silverlight的导航控件,实现翻页效果全部内容,希望文章能够帮你解决利用silverlight的导航控件,实现翻页效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)