废话不多说,在公司等我家妞儿下班顺便研究测试了一下一个对话框的组件,觉得挺不错的,推荐一下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);
}
}
}