两个页面之间创建带有动画的过渡效果基本步骤:
①截获当前任何表明用户正在离开当前页面的操作
②启动一个动画故事板来隐藏当前页面
③导航到下一个页面
④截获新页面的导航
⑤启动一个动画故事板来显示新页面
首先新建一个Windows Phone的应用程序
MainPage.xaml里面的动画效果代码:
01
02
03
04 Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
05 Storyboard.TargetName="phoneApplicationPage">
06
07
08
09
10 Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
11 Storyboard.TargetName="phoneApplicationPage">
12
13
14
15
16
17
18
19
然后拖一个Button控件,并触发Click事件,导航到Page1.xaml
1 private void button1_Click(object sender, RoutedEventArgs e)
2 {
3 this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
4 }
在MainPage.xaml.cs里面重写OnNavigatingFrom方法:
01 protected override voidOnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
02 {
03 base.OnNavigatingFrom(e);
04
05 if (UriToNavigateTo == null)
06 {
07 e.Cancel = true;
08 UriToNavigateTo = e.Uri;
09 this.HidePage.Begin();
10 this.HidePage.Completed += new EventHandler(HidePage_Completed);
11 }
12 else
13 {
14 UriToNavigateTo = null;
15 }
16 }
17
18 private void HidePage_Completed(object sender, EventArgs e)
19 {
20 this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
21 }
接着新建一个WindowsPhone页面Page1.xaml
Page1.xaml的动画效果代码如下:
01
02
03
04 Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)"
05 Storyboard.TargetName="phoneApplicationPage">
06
07
08
09
10 Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)"
11 Storyboard.TargetName="phoneApplicationPage">
12
13
14
15
16 Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
17 Storyboard.TargetName="phoneApplicationPage">
18
19
20
21
22
23
24
25
然后在Page1.xaml.cs的初始化函数里写如下代码:
view sourceprint?
1 public Page1()
2 {
3 InitializeComponent();
4
5 this.DisplayPage.Begin();
6 }
阅读(1914) | 评论(0) | 转发(0) |