在Windows Phone 7开发中,Coding4Fun组件提供的一些弹出框功能,要比原有MessageBox的效果好,这里向大家推荐下。在Coding4Fun的官网上,也有很多Demo效果可以预览。
Coding4Fun官网:http://coding4fun.codeplex.com/
里面有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);
- }