Windows Phone 之 EmailAddressChooserTask

來源:互聯網
上載者:User

  此文主要用於記錄如何使用EmailAddressChooserTask,該類主要用於選擇Windows Phone系統上已經儲存的Contract資訊,如:姓名,Email。類圖如下所示:

  示範例子如下,XAML:

<phone:PhoneApplicationPage
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"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
x:Class="SearchTask.MainPage"
xmlns:viewModel="clr-namespace:SearchTask.ViewModel"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.Resources>
<viewModel:MainPageView x:Key="ViewModel"/>
</Grid.Resources>
<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="My First Application" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="擷取連絡人" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" DataContext="{StaticResource ViewModel}" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<TextBox x:Name="SearchBox" Text="{Binding Contract, Mode=TwoWay}"/>
<Button x:Name="SearchBut" Content="GetContract" HorizontalAlignment="Left" VerticalAlignment="Top" Height="81" Margin="4,8,0,0" Grid.Row="1" Width="196" Background="#00C07777">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ec:CallMethodAction MethodName="GetContract" TargetObject="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</Grid>
</phone:PhoneApplicationPage>

ViewModel:

public class MainPageView : INotifyPropertyChanged
{
private EmailAddressChooserTask emailChooser;

public event PropertyChangedEventHandler PropertyChanged;

public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}

private string contract;

public string Contract
{
get
{
return contract;
}
set
{
contract = value;
PropertyChanged(this, new PropertyChangedEventArgs("Contract"));
}
}

public MainPageView()
{
emailChooser = new EmailAddressChooserTask();

emailChooser.Completed += new EventHandler<EmailResult>((obj, e) =>
{
//如果Error不等於Null,表明操作失敗
if (null == e.Error)
{
Contract = "Name: " + e.DisplayName + " Email: " + e.Email;
}
});
}

public void GetContract()
{
emailChooser.Show();
}
}

首次運行:

單擊GetContract按鈕:

任意選擇一條記錄:

運行結束,原始碼:http://files.cnblogs.com/PerfectSoft/EmailAddressChooserTask.zip

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.