1

在 Xaml 文件中我有

<ComboBox Grid.Row="2" Grid.Column="2" Margin="50,50,50,50" FontSize="50" SelectionChanged="NavigateKing">
        <ComboBoxItem></ComboBoxItem>
        <ComboBoxItem Content="Prince Wijaya"></ComboBoxItem>
        <ComboBoxItem Content="Pandukabhaya"></ComboBoxItem>
        <ComboBoxItem Content="Dewanampiya Tissa"></ComboBoxItem>
    </ComboBox>

在 Xaml.Cs 文件中

private void NavigateKing(object sender, SelectionChangedEventArgs e)
    {
        ComboBoxItem cbi = (ComboBoxItem)((sender as ComboBox).SelectedItem);
        string navigatingURI = cbi.Content.ToString();
        this.Frame.Navigate(typeof(/*IntendedXaml filename should be here*/);
    } 

我可以只传递 NavigationURI 来导航,而不是编写整个 if-else 或 switch-case 场景吗?

4

1 回答 1

1

尝试这个。

XAML

<ComboBox Margin="50,50,50,50" FontSize="50" SelectionChanged="NavigateKing">
    <ComboBoxItem Content="Prince Wijaya" Tag="BlankPage1"></ComboBoxItem>
    <ComboBoxItem Content="Pandukabhaya" Tag="BlankPage2"></ComboBoxItem>
    <ComboBoxItem Content="Dewanampiya Tissa" Tag="BlankPage3"></ComboBoxItem>
</ComboBox>

C#

private void NavigateKing(object sender, SelectionChangedEventArgs e)
{
    ComboBoxItem cbi = (ComboBoxItem)((sender as ComboBox).SelectedItem);
    string navigatingURI = cbi.Content.ToString();
    this.Frame.Navigate(Type.GetType(this.GetType().Namespace + "." + cbi.Tag.ToString()));
}
于 2013-10-23T19:53:15.593 回答