How to pass a parameter in a button and get value in the code behind to redirect to another page based on the value of parameter in windows phone 7?

Xiao Han picture Xiao Han · Jan 16, 2012 · Viewed 12.9k times · Source

I am thinking if the windows phone 7 button event is similar to ASP.NET development with C#, something like in the button, I set value to commandparameter in the XAML, and in the code behind, I get the commandparameter and redirect the page.

I haven't found any good examples for button event handling, any suggestions?

Thank you.

Answer

Teemu Tapanila picture Teemu Tapanila · Jan 16, 2012

For the xaml:

<Button Tag="pageAddress" Click="Button_Click" />

And then on the code-behind:

private void Button_Click(object sender, RoutedEventArgs e)
{
     Button _button = (Button)sender;
     NavigationService.Navigate(new System.Uri(_button.Tag.ToString()));
}