Address Chooser Task in Windows Phone

Windows Phone SDK provides the chooser “AddressChooserTask” that enables the users to retreive the physical address of the selected contact .

To use the Address Chooser Task in Windows Phone , follow the below steps

1. Add the namespace Microsoft.Phone.Tasks

2. Create an instance of the AddressChooserTask . Make sure that you declare the AddressChooserTask in the page scope and then add the event handler to the Completed property of the AddressChooserTask .

AddressChooserTask addressSelect;
addressSelect = new AddressChooserTask();
addressSelect.Completed += new EventHandler(addressSelect_Completed);

3. Call the Show method of the AddressChooserTask

addressSelect.Show();

4. This will launch the Contacts application where the user can select a contact , then the event “Completed” is raised which receives the address .

public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
AddressChooserTask addressSelect;
private void button1_Click(object sender, RoutedEventArgs e)
{
addressSelect = new AddressChooserTask();
addressSelect.Completed += new EventHandler(addressSelect_Completed);
addressSelect.Show();
}
void addressSelect_Completed(object sender, AddressResult e)
{
if (e.TaskResult == TaskResult.OK)
{
textBox1.Text = e.Address;
}
}
}

Leave a Reply