去年把windows phone手機的內建彈出框和Coding4Fun做了一個對比【http://blog.csdn.net/fengyarongaa/article/details/7077031】。今天就把操作類全部貼出來。
1.自己先下載一個Coding4Fun的dll檔案,然後引用到項目裡面,你懂的!
http://coding4fun.codeplex.com/
2.直接上代碼。
[csharp] view plaincopyprint?
- 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();
- }
- }
- }