For a simple menu I've used someting like the following several times.
<ListBox SelectionChanged="LinkSelected">
<ListBoxItem Name="EnterCode" >
<TextBlock Text="Enter Code" />
</ListBoxItem>
<ListBoxItem Name="Login" >
<TextBlock Text="Login" />
</ListBoxItem>
<ListBoxItem Name="Register" >
<TextBlock Text="Register" />
</ListBoxItem>
</ListBox>
And then something like this in the event handler:
private void WelcomeLinkSelected(object sender, SelectionChangedEventArgs e)
{
if (sender is ListBox)
{
if ((sender as ListBox).SelectedIndex < 0)
{
return;
}
if ((sender as ListBox).SelectedIndex == 0)
{
NavigationService.Navigate(new Uri("/EnterCode.xaml", UriKind.Relative));
}
if ((sender as ListBox).SelectedIndex == 1)
{
NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));
}
if ((sender as ListBox).SelectedIndex == 2)
{
NavigationService.Navigate(new Uri("/Register.xaml", UriKind.Relative));
}
// This is very important!
(sender as ListBox).SelectedIndex = -1;
}
}
If you do this, the last line in the event handler, which resets the SelectedIndex, is very important as it allows the same menu item to be selected multiple times in a row without first selecting another option.