用Windows Phone 7的MessageBox彈出框,總覺得不是很過癮,最近用了Coding4Fun組件提供了彈出框,感覺挺不錯的,很好用,在這裡推廣一下。Coding4Fun開源組件的:http://coding4fun.codeplex.com/ ,裡面有Demo。裡面還有其他的一些控制項也挺不錯的。
裡面有5種不同類型的彈窗
1.ToastPrompt:土司彈出框,類似於土司推播通知一樣的顯示效果,在螢幕上面出現一條訊息,然後再消失。
使用文法
private void Toast_Click(object sender, RoutedEventArgs e)
{
var toast = new ToastPrompt {
Title = "Basic",
Message = ToastLongMsg,
};
toast.Show();
}
2.AboutPrompt:說明彈出框,特點是彈出框會在螢幕中間,其他的彈出框是在螢幕的上方。
使用的文法:
private void About_Click(object sender, RoutedEventArgs e)
{
var about = new AboutPrompt();
about.Completed += baseObject_Completed;
about.Show();
}
void baseObject_Completed(object sender, PopUpEventArgs<object, PopUpResult> e)
{
if (e.PopUpResult == PopUpResult.Ok)
MessageBox.Show("OK!");
else if (e.PopUpResult == PopUpResult.Cancelled)
MessageBox.Show("CANCELLED!");
else
MessageBox.Show("meh?");
}
3.PasswordInputPrompt:密碼輸入彈出框,用於輸入密碼資訊。
private void Password_Click(object sender, RoutedEventArgs e)
{
var passwordInput = new PasswordInputPrompt
{
Title = "Basic Input",
Message = "I'm a basic input prompt",
};
passwordInput.Completed += input_Completed;
passwordInput.Show();
}
void input_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
{
if (e.PopUpResult == PopUpResult.Ok)
MessageBox.Show("You typed: " + e.Result);
else if (e.PopUpResult == PopUpResult.Cancelled)
MessageBox.Show("CANCELLED! " + e.Result);
else
MessageBox.Show("meh? " + e.Result);
}
4.InputPrompt:輸入彈出框,用於t彈出輸入框輸入其他的資訊。
private void Input_Click(object sender, RoutedEventArgs e)
{
var input = new InputPrompt
{
Title = "Basic Input",
Message = "I'm a basic input prompt",
};
input.Completed += input_Completed;
input.Show();
}
void input_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
{
if (e.PopUpResult == PopUpResult.Ok)
MessageBox.Show("You typed: " + e.Result);
else if (e.PopUpResult == PopUpResult.Cancelled)
MessageBox.Show("CANCELLED! " + e.Result);
else
MessageBox.Show("meh? " + e.Result);
}
5.MessagePrompt:訊息彈出框,普通的訊息彈出框,類似於系統預設的messagebox彈出框。
private void Message_Click(object sender, RoutedEventArgs e)
{
var messagePrompt = new MessagePrompt
{
Title = "Basic Message",
Message = "I'm a basic message prompt. ",
};
messagePrompt.Completed += stringObject_Completed;
messagePrompt.Show();
}
void stringObject_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
{
if (e.PopUpResult == PopUpResult.Ok)
MessageBox.Show("OK: " + e.Result);
else if (e.PopUpResult == PopUpResult.Cancelled)
MessageBox.Show("CANCELLED: " + e.Result);
else
MessageBox.Show("meh?: " + e.Result);
}
下面這張圖片基本上已經很形象地說明了這個控制項的屬性的含義了。
該彈出框控制項支援在彈窗內嵌入XAML檔案
把表示XAML控制項頁面的類賦值到Body屬性裡面
如
messagePrompt.Body =new BodyUserControl();
再放點美圖出來欣賞一下
最後面還有一篇美文來參考:
http://www.windowsphonegeek.com/articles/Coding4Fun-WP7-Message-Prompt-in-depth