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提示消息的更多相关文章

  1. jquery-模仿qq提示消息

    ( function() { var ua = navigator.userAgent.toLowerCase(); var is = (ua.match(/\b(chrome|opera|safar ...

  2. ZENG msgbox仿qq提示

    ZENG.msgbox.show("设置成功!", 4, 2000); ZENG.msgbox.show("服务器繁忙,请稍后再试.", 1, 2000); Z ...

  3. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  4. SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=》提升)

     SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=>提升,5个Demo贯彻全篇,感兴趣的玩才是真的学) 官方demo:http://www.asp.net/si ...

  5. Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制)

    Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制) 首先贴上七个控制布局代码 1.title_text_sel.xml 字体颜色的切换 放到color文件夹下面 <?xm ...

  6. Android 高仿QQ滑动弹出菜单标记已读、未读消息

    在上一篇博客<Android 高仿微信(QQ)滑动弹出编辑.删除菜单效果,增加下拉刷新功能>里,已经带着大家学习如何使用SwipeMenuListView这一开源库实现滑动列表弹出菜单,接 ...

  7. iOS天气动画、高仿QQ菜单、放京东APP、高仿微信、推送消息等源码

    iOS精选源码 TYCyclePagerView iOS上的一个无限循环轮播图组件 iOS高仿微信完整项目源码 想要更简单的推送消息,看本文就对了 ScrollView嵌套ScrolloView解决方 ...

  8. Socket实现仿QQ聊天(可部署于广域网)附源码(1)-简介

    1.前言 本次实现的这个聊天工具是我去年c#程序设计课程所写的Socket仿QQ聊天,由于当时候没有自己的服务器,只能在机房局域网内进行测试,最近在腾讯云上买了一台云主机(本人学生党,腾讯云有个学生专 ...

  9. < JAVA - 大作业(2)仿qq即时通讯软件 >

    < JAVA - 大作业(2)仿qq即时通讯软件 > 背景 JAVA上机大作业:设计一个仿qq即时通讯软件 任务简要叙述:设计一款仿QQ的个人用户即时通讯软件,能够实现注册,登陆,与好友聊 ...

随机推荐

  1. Node.js学习笔记(5)--文件简单操作

    说明(2017-5-3 11:53:45): 1. foo.js var fs = require("fs"); var documents = []; fs.readdir(&q ...

  2. golang的urlrouter

    起因 做权限管理,需要匹配路由,这个需要路由查找算法,一般采用tried 树,然而之前没研究过,一时半会也写不出来.在GitHub上找了一些router,然而都和http请求结合的很紧密,剥离一个纯粹 ...

  3. 加快Terminal的打开加载速度

    加快Terminal的打开加载速度html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMirr ...

  4. CentOS6.3升级Python到2.7.3版本

    http://www.zhangchun.org/the-centos6-3-upgrade-python-to-2-7-3-version/ 查看python的版本 1 python  -V  2 ...

  5. 【WPF】代码触发Button点击事件

    先定义Button按钮并绑定事件. public void test() { Button btn = new Button(); btn.Click += Btn_Click; } private ...

  6. (转) MyBatis(1)——快速入门

    MyBatis 简介 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为 ...

  7. mysql的骚操作:自增长的字段同时插入到另一个字段

    如题 ' ); select * from information_schema.tables where table_schema ='mytest' and table_name='users'; ...

  8. Android——音乐播放器完善——进度条显示当前播放进度,加可拖动进度条(未待解决完问题)

    效果: 问题:可拖动进度条随进度条移动时,会致使音乐卡顿(待解决) xml <?xml version="1.0" encoding="utf-8"?&g ...

  9. Knockout开发中文API系列3–使用计算属性

    计算属性 如果你已经有了一个监控属性 firstName和lastName,如果你想显示全名该怎么做呢?这个时候你就可以通过计算属性来实现,这个方法依赖于一个或多个监控属性,如果任何依赖对象发生改变他 ...

  10. Css+JS模拟实现可编辑的表格

    表格在未编辑状态和编辑状态,需要定义两个不同的样式. 比如未编辑状态是lable的样式,两边有两个括号[],表示该表格可以编辑:编辑中的表格则表示成一个input框,可以输入. 基本思路就是,在表格中 ...