我有以下代码,我为我的游戏级别菜单的每个按钮单击事件传递了一个参数。
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));
}
我的问题是,如何通过让所有按钮触发一次单击事件并传递唯一参数来更优雅地做到这一点?就像是
private void btnLevel_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePlay.xaml?parameter=[buttontag]", UriKind.Relative));
}