[英]How to navigate in XAML using a string as an argument to this.Frame.Navigate(typeof()?
in Xaml file I have 在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>
And in Xaml.Cs file 并在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*/);
}
Rather than writing a whole if-else or switch-case scenario can I just pass the NavigationURI to navigate? 除了编写整个if-else场景或切换案例场景,我还可以通过NavigationURI进行导航吗?
Try this. 尝试这个。
XAML 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# 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()));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.