廢話不多說,在公司等我家妞兒下班順便研究測試了一下一個對話方塊的組件,覺得挺不錯的,推薦一下Windows phone的開發人員。
首先下載一個第三方的組件,放在bin目錄裡面。:點擊開啟連結
其次我直接貼代碼
接下來是前台的XAML代碼:
<phone:PhoneApplicationPage x:Class="MicroBlogForWP7.AccountManager" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" shell:SystemTray.IsVisible="True" xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"> <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:Name="LayoutRoot" > <Grid.Background> <ImageBrush ImageSource="/Resource/Image/BS480480.png"></ImageBrush> </Grid.Background> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title--> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="ApplicationTitle" Text="Test" Foreground="DarkRed"/> <TextBlock x:Name="PageTitle" Text="測試頁" Margin="9,-7,0,0" Foreground="DarkRed" FontSize="55"/> </StackPanel> <!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Button Content="提示1" Foreground="DarkRed" Height="72" HorizontalAlignment="Left" Margin="47,33,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" /> <Button Content="提示2" Foreground="DarkRed" Height="72" HorizontalAlignment="Left" Margin="47,123,0,0" Name="button2" VerticalAlignment="Top" Width="160" Click="button2_Click" /> <Button Content="提示並輸入密碼" Foreground="DarkRed" Height="72" HorizontalAlignment="Left" Margin="47,216,0,0" Name="button3" VerticalAlignment="Top" Width="263" Click="button3_Click" /> <Button Content="提示並輸入帳號" Height="72" Foreground="DarkRed" HorizontalAlignment="Left" Margin="47,313,0,0" Name="button4" VerticalAlignment="Top" Width="263" Click="button4_Click" /> <Button Content="提示3" Foreground="DarkRed" Height="72" HorizontalAlignment="Left" Margin="76,414,0,0" Name="button5" VerticalAlignment="Top" Width="131" Click="button5_Click" /> </Grid> </Grid> </phone:PhoneApplicationPage>
最後是cs後台代碼:
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;using System.IO.IsolatedStorage;using Coding4Fun.Phone;using Coding4Fun.Phone.Controls;namespace MicroBlogForWP7{ public partial class AccountManager : PhoneApplicationPage { public AccountManager() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { var messagePrompt = new MessagePrompt { Title = "提示", Message = "錯誤的資訊提示", }; messagePrompt.Show(); } private void button2_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?"); } private void button3_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); } private void button4_Click(object sender, RoutedEventArgs e) { var input = new InputPrompt { Title = "Basic Input", Message = "I'm a basic input prompt", }; input.Completed += input_Completeds; input.Show(); } void input_Completeds(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); } private void button5_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); } }}