惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - kiminozo

UAP如何根据DeviceFamily显示不同的页面 Windows 10 响应式设计和设备友好的开发 Windows Phone Toolkit for WP8 已经出了 代码分享 ScrollViewerListener 获取ScrollViewer的位置改变 经验 C#手动同步的滥用实例 WP7技巧 扩展【共享...】按钮 Bangumi 番組計劃 WP手机客户端发布 WP7自定义控件 TabSwitch控件 模拟Windows phone 开始菜单的瓦片动画 WP7自定义控件 评分控件 WP7应用开发笔记 TiltEffect为控件添加倾斜的触控响应效果 从FLC中学习的设计模式系列-结构型模式(3)-享元模式 WP7应用开发笔记 继承BitmapSource并使用独立存储来缓存远程的图片 用代理类包装异步调用方法实现异步命令 解决log4net在.net 4.0 ClientProfile下无法使用 从FLC中学习的设计模式系列-结构型模式(2)-装饰 从FLC中学习的设计模式系列-结构型模式(1)-适配器 从FLC中学习的设计模式系列-创建型模式(5)-原型 从FLC中学习的设计模式系列-创建型模式(4)-建造者
WP7进阶技巧 自定义Toast 提示动画效果
kiminozo · 2012-03-22 · via 博客园 - kiminozo

Coding4Fun.Phone.Toolkit 这个库大家应该比较熟悉了吧,里面有一个ToastPrompt提供了本地Toast 方式提示,非常实用。可以参考我这篇文章WP7应用开发笔记(16) 本地Toast 提示

但是ToastPrompt的效果比较简单,如果需要扩展就比较麻烦,下面我来说明一下如何模拟新浪微博类似的Toast。

做之前首先看看SL的模拟效果吧:

无法观看,请下载直接下载示例 https://files.cnblogs.com/kiminozo/ToastPromptDemo.rar

了解DialogService

查看Coding4Fun的源代码,里面主要使用了DialogService类来实现的

http://blogs.claritycon.com/kevinmarshall/2010/10/13/wp7-page-transitions-sample/

DialogService的源代码请去Blog下载

比较重要的成员是

AnimationType 动画类型

Child 容器内的用于控件

IsBackKeyOverride 是否覆盖后退键

Overlay 覆盖颜色,null的情况不会影响触控操作。

Opened、Closed事件

Show()、Hide() 显示、隐藏

修改DialogService

需要自定义效果 需要修改Coding4Fun的源代码,

请去http://coding4fun.codeplex.com/releases/view/79749下载。

添加效果最重要的是增加AnimationType

默认只有2种Slide,Coding4Fun代码里面增加了2种SlideHorizontal

枚举如下

public enum AnimationTypes 
{
Slide,
SlideHorizontal,
Swivel,
SwivelHorizontal,
Vetical//new
}

为了实现我需要的效果,我添加了一种名叫Vetical的动画类型。

为这个类型添加2个Storyboard

private const string VeticalInStoryboard = 
@"<Storyboard xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.RenderTransform).(TranslateTransform.Y)"">
<EasingDoubleKeyFrame KeyTime=""0"" Value=""-50""/>
<EasingDoubleKeyFrame KeyTime=""0:0:2"" Value=""0"">
<EasingDoubleKeyFrame.EasingFunction>\
<ExponentialEase EasingMode=""EaseInOut"" Exponent=""6""/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetProperty=""(UIElement.Opacity)"" From=""0"" To=""1"" Duration=""0:0:2""
Storyboard.TargetName=""LayoutRoot"">
<DoubleAnimation.EasingFunction>
<ExponentialEase EasingMode=""EaseOut"" Exponent=""6""/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
";

private const string VeticalOutStoryboard =
@"<Storyboard xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.RenderTransform).(TranslateTransform.Y)"">
<EasingDoubleKeyFrame KeyTime=""0"" Value=""0""/>
<EasingDoubleKeyFrame KeyTime=""0:0:1"" Value=""-50"">
<EasingDoubleKeyFrame.EasingFunction>\
<ExponentialEase EasingMode=""EaseInOut"" Exponent=""6""/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetProperty=""(UIElement.Opacity)"" From=""1"" To=""0"" Duration=""0:0:1""
Storyboard.TargetName=""LayoutRoot"">
<DoubleAnimation.EasingFunction>
<ExponentialEase EasingMode=""EaseIn"" Exponent=""6""/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
";

找到Show()的代码,在switch中添加

case AnimationTypes.Vetical: 
storyboard = XamlReader.Load(VeticalInStoryboard) as Storyboard;
_overlay.RenderTransform = new TranslateTransform();
break;

Hide()同理

然后找到Coding4Fun的ToastPrompt类,修改Show()里面的

AnimationType = DialogService.AnimationTypes.Vetical,

如下:

public void Show() 
{
..

dialogService = new DialogService
{
AnimationType = DialogService.AnimationTypes.Vetical,
Child = this,
IsBackKeyOverride = true
};

...

}

当然也可以使用面向对象的知识多态化ToastPrompt,这里就不详细描述了。