I have the following code that I pass a single parameter for each button click event for my game level menu.
private void btnLevelVeryEasy_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=0", UriKind.Relative));
}
private void btnLevelEasy_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=1", UriKind.Relative));
}
private void btnLevelMedium_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=2", UriKind.Relative));
}
private void btnLevelHard_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=3", UriKind.Relative));
}
private void btnLevelInsane_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=4", UriKind.Relative));
}
My question is, how to do it more elegantly by having all the buttons fire one click event and pass unique parameter? Something like
private void btnLevel_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=[buttontag]", UriKind.Relative));
}
Sayse almost got it right, except the .Name should be after the ():
EDIT:
OP, you do know how to link the event on each button do you? (In events just click the dropdown menu and select the previous created event)