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. iosg给父类view添加透明度子类也变得透明

    用如下方式给父类view设置透明度不要使用alpha设置 self.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponen ...

  2. python. pandas(series,dataframe,index) method test

    python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...

  3. font-face 跨域解决

    nginx 里设置@font-face 跨域 server { ... # Fix @font-face cross-domain restriction in Firefox location ~* ...

  4. flume1.8实现hdfsSink整点滚动文件

    由于官方的1.8版本hdfs-sink不能在每天的0点滚动文件,所以修改了flume-hdfs-sink源码. flume-hdfs-sink中修改了HDFSEventSink.java文件,其他文件 ...

  5. 使用jquery将表单元素转json提交后台

    今天帮朋友解决一个问题,朋友的框架用的layui的,发现layui的里面的data.field不能获取动态生成的标签的值的. 于是使用jquery的方法如下: var formObject = {}; ...

  6. sql 拼接同列的值

    sql中有时需要将列的值转成行的形式,比如下面的数据,具有相同Path的ZumenID有哪一些,该怎么做呢? 常见的做法可以参见这篇文章http://www.cnblogs.com/xiashengw ...

  7. Navi.Soft31.开发工具(含下载地址)

    1系统简介 1.1功能简述 在软件开发过程中,我们需要经常对字符串.文件.数据库操作.有时需要浏览Json格式串,有时需要浏览Xml格式串,有时需要读取txt或excel文件,有时需要对数据库访问.本 ...

  8. Android安装后没有完成和打开按钮

    File apkFile = new File(filePath); Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVIT ...

  9. MATLAB2012a_for_win7_64

    matlab 2012b是mathworks官网发布的一款功能强大.性能稳定的商业数学软件,新版本采用了全新的视图界面,具有MATLAB和Simulink的重大更新,可显著提升用户的使用与导航体验.比 ...

  10. ASP.NET中使用jQuery插件实现图片幻灯效果

    参照网上的资料及提供的jQuery插件实现图片幻灯效果. 1.页面前台代码: //头部引用 <head runat="server"><title>< ...