In this exercise, you will change the TextBlock controls to HyperlinkButtons. You will add the methods necessary to for the On Click events to call the appropriate launcher for the button. The Windows Phone 7 application will enable the user to place a phone call or compose an e-mail message from SharePoint Contact list data.
Task 1 – Beginning the Exercise
In this task, you will open the lab solution in Visual Studio 2010.
- Make sure that you have downloaded and installed the items listed in System Requirements above prior to beginning this exercise.
- Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open » Project.
- Browse to the WP7.SharePoint.ClickAction.sln file located at %TrainingKitPath%\Labs\AddingLauncherstoEMailAndPhoneNumbers\Source\Before\ and select it.
- Click Open to open the solution.
Task 2 – Configuring Constants in the Windows Phone 7 Application
In this task, you will configure the constants used in the Windows Phone 7 application to work with your development environment.
- In the WP7.SharePoint.People project, in the Utilities folder, open the Constants.cs file.
- Change the value for the USER_NAME and USER_PASSWORD constants to represent a Forms Based Authentication user specific to your development environment. For this lab, the user requires read and write permissions.
- Change the value for the AUTHENTICATION_SERVICE_URL constant to the URL specific to your development environment.
The following code example demonstrates the value for a SharePoint server named fbawp7.
public const string AUTHENTICATION_SERVICE_URL = "https://fbawp7/_vti_bin/authentication.asmx";
Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service
In this task, you will configure the reference to the SharePoint lists.asmx Web service. The service reference to this Web service has already been added to the project.
- In the Solution Explorer, double click the ServiceReferences.ClientConfig file to open it.
- In the Endpoint element, change the address attribute to the URL for the lists.asmx SharePoint Web service in the site where you created the Sample Tasks list.
Example: https://fbawp7/_vti_bin/lists.asmx
Figure 1
Client Configuration Endpoint address
In this task, you will edit the user interface to display the Work Phone and Email fields as Hyperlink Buttons that a user can use to send a message or place a call.
- In the WP7.SharePoint.ClickAction project, double click the ContactView.xaml file.
Add the following code under the <!-- TODO: 10.4.1 Add the EMail HyperlinkButton -->.
<HyperlinkButton Content="{Binding DataModel.EMail}" Height="72" HorizontalAlignment="Left" x:Name="EMailLink" VerticalAlignment="Bottom" Width="450" ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource PhoneHyperlinkButtonStyle}" Click="EMailLink_Click" />
Add the following code under the <!-- TODO: 10.4.2 Add the Phone HyperlinkButton -->.
<HyperlinkButton Content="{Binding DataModel.WorkPhone}" Height="72" HorizontalAlignment="Left" x:Name="PhoneLink" Width="450" ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource PhoneHyperlinkButtonStyle}" Click="PhoneLink_Click" />
Task 5 – Implementing Code to Send an E-Mail Message
In this task, you will add the code required to send an email and place a phone call.
- In the WP7.SharePoint.ClickAction project, double click the ContactView.xaml.cs file.
Add the following code under the //TODO: 10.4.3 comment to define the EmailLink_Click event handler:
private void EMailLink_Click(object sender, RoutedEventArgs e) { //Before you leave the app, store the current item PhoneApplicationService.Current.State["ActiveItem"] = (viewModel.DataModel as SPContact); //Create a new task EmailComposeTask task = new EmailComposeTask(); //Add the current item’s EMail address task.To = viewModel.DataModel.EMail; //Just a little text for the message task.Subject = "Hello from the Contact App"; //Launch the task task.Show(); }
Add the following code under the //TODO: 10.4.4 comment to define the PhoneLink_Click event handler:
private void PhoneLink_Click(object sender, RoutedEventArgs e) { //Create a new Phone Call task PhoneCallTask task = new PhoneCallTask(); //Pass the current contacts phone number task.PhoneNumber = viewModel.DataModel.WorkPhone; //Display thier full name task.DisplayName = viewModel.DataModel.FullName; //Launch the task task.Show(); }
- The event handlers above use the data from the current ViewModel to populate the properties of their respective tasks before launching the task.
Task 6 – Testing the Application
In this task, you will test the Windows Phone 7 application.
- In the WP7.SharePoint.ClickAction solution, select Windows Phone 7 Emulator in the deployment location dropdown list.
- Press F5.
The Windows Phone 7 application starts in the emulator. The application will initially display the three contacts that you added to the contact list. Clicking any contact will navigate the application to the Contact View page.
Figure 2
Contacts from SharePoint
Notice that the Work Phone number and E-Mail address are displayed as clickable links on the details page.
Figure 3
Clickable details on the details page
Click the Phone Number field and Windows Phone 7 confirms your request to dial the number. Click don’t call.
Figure 4
Phone call confirmation
On the emulator, you will not be able to dial a number or send an e-mail. Both of these activities require a physical Windows Phone 7 device. This lab is for demonstration purposes only. If you have a physical device, you may deploy to it and test this functionality by changing your deployment target to Windows Phone 7 Device.
Click the e-mail link. You will receive a “Can’t Send” error on the emulator.
Figure 5
Windows Phone E-Mail Configuration Error
- Click close to return to the application.