去年把windows phone手机的自带弹出框和Coding4Fun做了一个对比【http://blog.csdn.net/fengyarongaa/article/details/7077031】。今天就把操作类全部贴出来。
1.自己先下载一个Coding4Fun的dll文件,然后引用到项目里面,你懂的!
下载地址http://coding4fun.codeplex.com/
2.直接上代码。
- using System;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using Coding4Fun.Phone;
- using Coding4Fun.Phone.Controls;
- //@yr.feng
- namespace MicroBlogForWP7.Classes.Util
- {
- /// <summary>
- /// 对话框
- /// </summary>
- public class Msg
- {
- /// <summary>
- /// 带有"确定"和"取消"按钮消息提示框。返回值为bool类型
- /// </summary>
- /// <param name="content">提示的信息内容</param>
- /// <param name="title">提示的标题</param>
- /// <returns>ture or false</returns>
- public bool ReturnConfirfMsg(string content, string title)
- {
- MessageBoxResult m = MessageBox.Show(content, title, MessageBoxButton.OKCancel);
- if (m == MessageBoxResult.OK)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 带有"确定"按钮消息提示框。返回值为bool类型
- /// </summary>
- /// <param name="content">提示的信息内容</param>
- /// <param name="title">提示的标题</param>
- /// <returns>ture or false</returns>
- public bool ReturnConfirfMsgByOk(string content, string title)
- {
- MessageBoxResult m = MessageBox.Show(content, title, MessageBoxButton.OK);
- if (m == MessageBoxResult.OK)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 带"确定"按钮的消息提示框。不具有返回值
- /// </summary>
- /// <param name="content">提示的信息内容</param>
- /// <param name="title">提示的标题</param>
- public void ConfirfMsgForOK(string content, string title)
- {
- MessageBox.Show(content, title, MessageBoxButton.OK);
- }
- /// <summary>
- /// 带"确定"和"取消"按钮的消息提示框。不具有返回值
- /// </summary>
- /// <param name="content">提示的信息内容</param>
- /// <param name="title">提示的标题</param>
- public void ConfirfMsgForOKCancel(string content, string title)
- {
- MessageBox.Show(content, title, MessageBoxButton.OKCancel);
- }
- /// <summary>
- /// 使用Coding4Fun组件的淡入淡出对话框。不具有返回值
- /// </summary>
- /// <param name="content">提示的信息内容</param>
- /// <param name="title">提示的标题</param>
- /// <param name="timeout">提示消息的显示过期时间。单位毫秒</param>
- public void Coding4FunForMsg(string content, string title, int timeout)
- {
- SolidColorBrush White = new SolidColorBrush(Colors.White);
- SolidColorBrush Red = new SolidColorBrush(Colors.Brown);
- ToastPrompt toast = new ToastPrompt
- {
- Background = Red,
- IsTimerEnabled = true,
- IsAppBarVisible = true,
- MillisecondsUntilHidden = timeout,
- Foreground = White,
- };
- toast.Title = title;
- toast.Message = content;
- toast.TextOrientation = System.Windows.Controls.Orientation.Horizontal;
- toast.Show();
- }
- }
- }