【WP8】仿QQ提示消息
WP版的QQ提示消息的时候从顶部滑入,3秒后从顶部滑出,本文模仿该效果实现一个MessageToastManager类用于显示提示消息
思路很简单,就是动画而已,支持配置颜色和回掉
// *************************************************
//
// 作者:bomo
// 小组:WP开发组
// 创建日期:2014/7/7 15:18:12
// 版本号:V1.00
// 说明:
//
// *************************************************
//
// 修改历史:
// Date WhoChanges Made
// 2014/7/7 15:18:12 bomo Initial creation
//
// ************************************************* using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Media.Animation; namespace XTuOne.Utility.Helpers
{
/// <summary>
/// 消息提示工具
/// </summary>
public class MessageToastManager
{
private static readonly Color defaultForegroundColor = Color.FromArgb(, , , );
private static readonly Color defaultBackgroundColor = Colors.White; public static void Show(string text, Action complete = null, double height = )
{
Show(text, defaultForegroundColor, defaultBackgroundColor, complete, height);
} public static void Show(string text, Color foregroundColor, Color backgroundColor, Action complete = null, double height = )
{
Show(text, new SolidColorBrush(foregroundColor), new SolidColorBrush(backgroundColor), complete, height);
} public static void Show(string text, Brush foregroundBrush, Brush backgroundBrush, Action complete = null, double height = )
{
var p = new Popup
{
Child = new Border
{
Width = Application.Current.Host.Content.ActualWidth,
Background = backgroundBrush,
Child = new TextBlock
{
Text = text,
Foreground = foregroundBrush,
FontSize = (double)Application.Current.Resources["PhoneFontSizeNormal"],
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(, , , )
}
}
}; Show(p, complete, height);
} private static void Show(Popup popup, Action complete = null, double height = )
{
if (!(popup.Child.RenderTransform is CompositeTransform))
{
popup.Child.RenderTransform = new CompositeTransform();
}
((CompositeTransform)popup.Child.RenderTransform).TranslateY = -height; Debug.Assert(popup.Child is FrameworkElement); var element =popup.Child as FrameworkElement;
element.Height = height; var storyboard = new Storyboard
{
AutoReverse = false
}; var doubleAnimaionUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(doubleAnimaionUsingKeyFrames, popup.Child);
Storyboard.SetTargetProperty(doubleAnimaionUsingKeyFrames, new PropertyPath("(UIElement.Opacity)", new object[]));
storyboard.Children.Add(doubleAnimaionUsingKeyFrames); //0.5秒透明度从0-1
var doubleKeyFrame = new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5)),
Value = ,
EasingFunction = new CubicEase {EasingMode = EasingMode.EaseOut}
};
doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
doubleKeyFrame = new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.4)),
Value = 0.995,
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
doubleKeyFrame = new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds()),
Value = 0.1,
};
doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame); doubleAnimaionUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(doubleAnimaionUsingKeyFrames, popup.Child);
Storyboard.SetTargetProperty(doubleAnimaionUsingKeyFrames, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)", new object[]));
storyboard.Children.Add(doubleAnimaionUsingKeyFrames);
doubleKeyFrame = new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5)),
Value = ,
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
};
doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
doubleKeyFrame = new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.4)),
Value = ,
};
doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
doubleKeyFrame = new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds()),
Value = -height,
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame); var objectAnimaionUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
Storyboard.SetTarget(objectAnimaionUsingKeyFrames, popup);
Storyboard.SetTargetProperty(objectAnimaionUsingKeyFrames, new PropertyPath("(Popup.IsOpen)", new object[]));
storyboard.Children.Add(objectAnimaionUsingKeyFrames); var discreteObjectKeyFrame = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds()),
Value = true
};
objectAnimaionUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame); discreteObjectKeyFrame = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds()),
Value = false
};
objectAnimaionUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame); if (complete!=null)
{
storyboard.Completed += (s, e) => complete.Invoke();
} storyboard.Begin();
}
}
}
【WP8】仿QQ提示消息的更多相关文章
- jquery-模仿qq提示消息
( function() { var ua = navigator.userAgent.toLowerCase(); var is = (ua.match(/\b(chrome|opera|safar ...
- ZENG msgbox仿qq提示
ZENG.msgbox.show("设置成功!", 4, 2000); ZENG.msgbox.show("服务器繁忙,请稍后再试.", 1, 2000); Z ...
- wpf实现仿qq消息提示框
原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...
- SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=》提升)
SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=>提升,5个Demo贯彻全篇,感兴趣的玩才是真的学) 官方demo:http://www.asp.net/si ...
- Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制)
Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制) 首先贴上七个控制布局代码 1.title_text_sel.xml 字体颜色的切换 放到color文件夹下面 <?xm ...
- Android 高仿QQ滑动弹出菜单标记已读、未读消息
在上一篇博客<Android 高仿微信(QQ)滑动弹出编辑.删除菜单效果,增加下拉刷新功能>里,已经带着大家学习如何使用SwipeMenuListView这一开源库实现滑动列表弹出菜单,接 ...
- iOS天气动画、高仿QQ菜单、放京东APP、高仿微信、推送消息等源码
iOS精选源码 TYCyclePagerView iOS上的一个无限循环轮播图组件 iOS高仿微信完整项目源码 想要更简单的推送消息,看本文就对了 ScrollView嵌套ScrolloView解决方 ...
- Socket实现仿QQ聊天(可部署于广域网)附源码(1)-简介
1.前言 本次实现的这个聊天工具是我去年c#程序设计课程所写的Socket仿QQ聊天,由于当时候没有自己的服务器,只能在机房局域网内进行测试,最近在腾讯云上买了一台云主机(本人学生党,腾讯云有个学生专 ...
- < JAVA - 大作业(2)仿qq即时通讯软件 >
< JAVA - 大作业(2)仿qq即时通讯软件 > 背景 JAVA上机大作业:设计一个仿qq即时通讯软件 任务简要叙述:设计一款仿QQ的个人用户即时通讯软件,能够实现注册,登陆,与好友聊 ...
随机推荐
- 迭代器模式和组合模式(head first设计模式——8)
把迭代器模式和组合模式放在同一篇的原因是其联系比较紧密. 一.迭代器模式 1.1迭代器模式定义 迭代器模式提供一种方法顺序访问一个聚合对象中的各个元素,而不是暴露其内部的表示. 这个模式提供了一种方法 ...
- 微信web开发者工具同时打开两个小程序项目
在写小程序时,想要一边参考别人的Demo一边做,但是微信web开发者工具无法同时开两个实例,怎么办? 单个软件实例来回切换打开的项目太麻烦,一种办法是同时下载[微信web开发者工具]和[微信web开发 ...
- Win10下打开chm文档提示无法显示该页的解决方法
一是检查chm文件属性里最下面是否有个“解除锁定”,如有,点击“解除锁定”按钮就可以了. 如果没有上面提到的“解除锁定”,检查chm文件存放的路径.本例中,由于chm文件的存放路径中不能带有特殊字符“ ...
- prepareEditor
@Override public Component prepareEditor(TableCellEditor editor, int row, int column) { final Compon ...
- 枚举Enum和常量0之间的恩怨
1,任何为0的常量表达式都能隐式的转换成枚举Enum. 对于这一点,在程序中没少吃苦头.特别是对于函数重载的情况,往往让人一头雾水. 看看下面的代码(摘自MSDN),你能猜到输出吗? public e ...
- Drupal Nginx伪静态设置方法
location ~ ^.*/files\/styles\/.*$ { access_log off; expires 45d; error_page @drupal; } location @dru ...
- HBase解决海量图片存储方案
随着互联网.云计算及大数据等信息技术的发展,越来越多的应用依赖于对海量数据的存储和处理,如智能监控.电子商务.地理信息等,这些应用都需要对海量图片的存储和检索.由于图片大多是小文件(80%大小在数MB ...
- 提高Java代码质量的Eclipse插件之Checkstyle的使用具体解释
CheckStyle是SourceForge下的一个项目,提供了一个帮助JAVA开发者遵守某些编码规范的工具.它可以自己主动化代码规范检查过程.从而使得开发者从这项重要可是枯燥的任务中解脱出来. Ch ...
- 解決BufferedReader读取UTF-8文件中文乱码(转)
读取txt文件乱码 BufferedReader read = new BufferedReader(new FileReader(new File(filename))); 解决办法: InputS ...
- jQuery(八):属性操作
一.获取或设置元素的属性值 attr()获取或设置匹配元素的属性值,语法如下: 获取元素属性值示例: <!DOCTYPE html> <html lang="en" ...