Windows Phone-based EmailAddressChooserTask

Source: Internet
Author: User

This article is mainly used to record how to use EmailAddressChooserTask. This class is mainly used to select the Contract information that has been stored on the Windows Phone System, such as name and Email. The class diagram is as follows:

The demo is as follows:

<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 = ",">
<TextBlock x: Name = "ApplicationTitle" Text = "My First Application" Style = "{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x: Name = "PageTitle" Text = "get contact" 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" verticalignment = "Top" Height = "81" Margin = "," 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) =>
{
// If Error is not Null, the operation fails.
If (null = e. Error)
{
Contract = "Name:" + e. DisplayName + "Email:" + e. Email;
}
});
}

Public void GetContract ()
{
EmailChooser. Show ();
}
}

First run:

Click the GetContract button:

Select any record:

Run ended, source code: http://files.cnblogs.com/PerfectSoft/EmailAddressChooserTask.zip

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.