博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
<wp8>_______关键帧动画(DoubleAnimationUsingKeyFrames)、自定义对话框
阅读量:5747 次
发布时间:2019-06-18

本文共 10648 字,大约阅读时间需要 35 分钟。

using System;using System.Windows;using System.Windows.Media;using System.Windows.Input;using Microsoft.Phone.Shell;using System.Windows.Controls;using Microsoft.Phone.Controls;using System.Windows.Media.Animation;using System.Windows.Controls.Primitives;namespace CustCtrlClassLibrary{    public partial class PopupView : UserControl    {        #region Constructor        private bool IsAutoClose = true;        private int storyType = 0;        public PopupView(PhoneApplicationPage basePage, bool isAutoClose, int storytype = 0)        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(PopupCotainer_Loaded);            _BasePage = basePage; IsAutoClose = isAutoClose; storyType = storytype;            _BasePage.BackKeyPress += BasePage_BackKeyPress;        }        #endregion        #region Property        private PhoneApplicationPage _BasePage;        private FrameworkElement _PopupContent { get; set; }        Popup _Popup;        CubicEase _EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseInOut };        public bool IsShown        {            get            {                return _Popup.IsOpen;            }        }        #endregion        #region Private Method        private void PopupCotainer_Loaded(object sender, RoutedEventArgs e)        {            if (_BasePage.ApplicationBar != null)                _BasePage.ApplicationBar.IsVisible = false;            if (storyType == 0) {                PrepareShowStory().Begin();            } else if (storyType == 1) {                LaunchDialog().Begin();            }        }        private void BasePage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)        {            this.Close();            e.Cancel = true;        }        private Storyboard PrepareShowStory()        {            contentArea.Children.Add(_PopupContent);            UpdateLayout();            Storyboard story = new Storyboard();            DoubleAnimation animation;            animation = new DoubleAnimation();            animation.From = 0 - popupArea.ActualHeight;            animation.To = SystemTray.IsVisible ? 32 : 0;            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));            animation.EasingFunction = _EasingFunction;            Storyboard.SetTarget(animation, popupTransform);            Storyboard.SetTargetProperty(animation, new PropertyPath("TranslateY"));            story.Children.Add(animation);            animation = new DoubleAnimation();            animation.From = 0;            animation.To = 0.5;            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));            Storyboard.SetTarget(animation, mask);            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));            story.Children.Add(animation);            return story;        }        private Storyboard PrepareCloseStory()        {            Storyboard story = new Storyboard();            DoubleAnimation animation;            story.Completed += new EventHandler(StoryReverse_Completed);            animation = new DoubleAnimation();            animation.From = popupTransform.TranslateY;            animation.To = 0 - popupArea.ActualHeight;            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));            animation.EasingFunction = _EasingFunction;            Storyboard.SetTarget(animation, popupTransform);            Storyboard.SetTargetProperty(animation, new PropertyPath("TranslateY"));            story.Children.Add(animation);            animation = new DoubleAnimation();            animation.From = mask.Opacity;            animation.To = 0;            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));            Storyboard.SetTarget(animation, mask);            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));            story.Children.Add(animation);            return story;        }        private Storyboard LaunchDialog()        {            contentArea.Children.Add(_PopupContent);            UpdateLayout();            //装载DoubleAnimationUsingKeyFrames动画的故事板            Storyboard keyFrameboard = new Storyboard();            #region 后台代码添加DoubleAnimationUsingKeyFrames动画            DoubleAnimationUsingKeyFrames dakeyframe = new DoubleAnimationUsingKeyFrames();            //设置border矩形控件的Opacity透明度,并且开始动画事件为0秒的时候。            Storyboard.SetTarget(dakeyframe, contentArea);            Storyboard.SetTargetProperty(dakeyframe, new PropertyPath("UIElement.Opacity"));            dakeyframe.BeginTime = new TimeSpan(0, 0, 0);            //添加一个在第0.05秒的时候Opacity透明度值为1的关键帧            SplineDoubleKeyFrame SKeyFrame = new SplineDoubleKeyFrame();            SKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.03));            SKeyFrame.Value = 1;            dakeyframe.KeyFrames.Add(SKeyFrame);            keyFrameboard.Children.Add(dakeyframe);            #endregion            #region 后台代码添加DoubleAnimationUsingKeyFrames动画            DoubleAnimationUsingKeyFrames dakeyscaleX = new DoubleAnimationUsingKeyFrames();            //设置border矩形控件的ScaleX透明度,并且开始动画事件为0秒的时候。            Storyboard.SetTarget(dakeyscaleX, contentArea);            Storyboard.SetTargetProperty(dakeyscaleX, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleX)"));            dakeyscaleX.BeginTime = new TimeSpan(0, 0, 0);            //添加一个在第0秒的时候ScaleX透明度值为0.5的关键帧            EasingDoubleKeyFrame EKeyFrameX = new EasingDoubleKeyFrame();            EKeyFrameX.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));            EKeyFrameX.Value = 0.5;            dakeyscaleX.KeyFrames.Add(EKeyFrameX);            //添加一个在第0.15秒的时候ScaleX透明度值为1.1的关键帧            EKeyFrameX = new EasingDoubleKeyFrame();            EKeyFrameX.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1));            EKeyFrameX.Value = 1.1;            dakeyscaleX.KeyFrames.Add(EKeyFrameX);            //添加一个在第0.25秒的时候ScaleX透明度值为0.9的关键帧            EKeyFrameX = new EasingDoubleKeyFrame();            EKeyFrameX.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2));            EKeyFrameX.Value = 0.9;            dakeyscaleX.KeyFrames.Add(EKeyFrameX);            //添加一个在第0.3秒的时候ScaleX透明度值为0.9的关键帧            EKeyFrameX = new EasingDoubleKeyFrame();            EKeyFrameX.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.25));            EKeyFrameX.Value = 1.0;            dakeyscaleX.KeyFrames.Add(EKeyFrameX);            keyFrameboard.Children.Add(dakeyscaleX);            #endregion            #region 后台代码添加DoubleAnimationUsingKeyFrames动画            DoubleAnimationUsingKeyFrames dakeyscaleY = new DoubleAnimationUsingKeyFrames();            //设置border矩形控件的ScaleY透明度,并且开始动画事件为0秒的时候。            Storyboard.SetTarget(dakeyscaleY, contentArea);            Storyboard.SetTargetProperty(dakeyscaleY, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleY)"));            dakeyscaleY.BeginTime = new TimeSpan(0, 0, 0);            //添加一个在第0秒的时候ScaleX透明度值为0.5的关键帧            EasingDoubleKeyFrame EKeyFrameY = new EasingDoubleKeyFrame();            EKeyFrameY.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));            EKeyFrameY.Value = 0.5;            dakeyscaleY.KeyFrames.Add(EKeyFrameY);            //添加一个在第0.15秒的时候ScaleX透明度值为1.1的关键帧            EKeyFrameY = new EasingDoubleKeyFrame();            EKeyFrameY.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1));            EKeyFrameY.Value = 1.1;            dakeyscaleY.KeyFrames.Add(EKeyFrameY);            //添加一个在第0.25秒的时候ScaleX透明度值为0.9的关键帧            EKeyFrameY = new EasingDoubleKeyFrame();            EKeyFrameY.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2));            EKeyFrameY.Value = 0.9;            dakeyscaleY.KeyFrames.Add(EKeyFrameY);            //添加一个在第0.3秒的时候ScaleX透明度值为0.9的关键帧            EKeyFrameY = new EasingDoubleKeyFrame();            EKeyFrameY.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.25));            EKeyFrameY.Value = 1.0;            dakeyscaleY.KeyFrames.Add(EKeyFrameY);            keyFrameboard.Children.Add(dakeyscaleY);            #endregion            return keyFrameboard;        }        private Storyboard CloseDialog()        {            Storyboard keyFrameboard = new Storyboard();            keyFrameboard.Completed += new EventHandler(StoryReverse_Completed);            DoubleAnimation animation = new DoubleAnimation();            //设置border矩形控件的Opacity透明度,并且开始动画事件为0秒的时候。            Storyboard.SetTarget(animation, contentArea);            Storyboard.SetTargetProperty(animation, new PropertyPath("UIElement.Opacity"));            animation.From = 1; animation.To = 0.1;            animation.Duration = new Duration(TimeSpan.FromSeconds(0.1));            keyFrameboard.Children.Add(animation);            return keyFrameboard;        }        private void StoryReverse_Completed(object sender, EventArgs e)        {            ClosePopup();        }        private void ClosePopup()        {            contentArea.Children.Clear();            _PopupContent = null;            _BasePage = null;            Popup parent = this.Parent as Popup;            if (parent != null)            {                parent.IsOpen = false;            }        }        private void mask_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)        {            if (IsAutoClose)                Close();        }        #endregion        #region Public Method        public void Show(FrameworkElement popupContent)        {            _PopupContent = popupContent;            _Popup = new Popup();            _Popup.Child = this;            _Popup.IsOpen = true;        }        public event PopUpClosed nPopUpClosed;        public void Close()        {            _BasePage.BackKeyPress -= BasePage_BackKeyPress;            if (storyType == 0) {                PrepareCloseStory().Begin();            } else if (storyType == 1) {                CloseDialog().Begin();            }            if (_BasePage.ApplicationBar != null)                _BasePage.ApplicationBar.IsVisible = true;            if (nPopUpClosed != null)                nPopUpClosed();        }        #endregion        public void SetBackgroundColor(Brush aBrush)        {            contentArea.Background = aBrush;        }    }}
CustCtrl parm = new CustCtrl();PopupView pc = new PopupView(this, false, 1);pc.Height = this.ActualHeight; pc.Width = this.ActualWidth;SolidColorBrush nBrush = new SolidColorBrush(Color.FromArgb(25, 68, 68, 68));pc.SetBackgroundColor(nBrush); pc.Show(parm);

 

转载于:https://www.cnblogs.com/qq278360339/archive/2013/03/29/2988611.html

你可能感兴趣的文章
《Docker生产环境实践指南》——2.3 宿主机管理
查看>>
《Android游戏开发详解》——第2章,第2.17节对象是独立的
查看>>
《好学的C++程序设计》——第1章 概论
查看>>
《Adobe Flash CS5中文版经典教程》——1.9 预览影片
查看>>
《HTML5+CSS3网页设计入门必读》——2.7 我们不使用这种语言
查看>>
想谈恋爱?来对个暗号先!
查看>>
Linux 内核的测试和调试(6)
查看>>
11张图带你走过数据可视化的前生今世
查看>>
关于鼠标滚轮事件的禁止方法
查看>>
ASM 翻译系列第三十五弹:ASM 253号文件——ASM spfile
查看>>
[快速技巧]如何设定你的 Ubuntu 14.04 自动关机
查看>>
《JavaScript入门经典(第6版)》——1.10 作业
查看>>
演讲实录丨陈天 基于表现性评价的综合问题解决能力评估
查看>>
《Access 2007开发指南(修订版)》一一2.13 检查表特殊性和局限性
查看>>
《Swift入门经典(第2版)》——第1章 Swift开发环境简介 1.1什么是Swift
查看>>
编程即人生:从编代码中学到的三条生活感悟
查看>>
《OpenGL ES 2.0游戏开发(上卷):基础技术和典型案例》——6.3节定位光与定向光...
查看>>
《iOS和tvOS 2D游戏开发教程》——第2章,第2.4节挑战
查看>>
4月14日云栖精选夜读:EDAS-如何快速定位OOM问题【云享团】
查看>>
后续《2013—I want to talk with the world》
查看>>