按钮单击UWP时,使用选中的组合框项目导航到新页面 [英] Navigating to new page with selcted combobox item when button is click UWP
本文介绍了按钮单击UWP时,使用选中的组合框项目导航到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我希望用户选择组合框中的项目,当他们按下按钮时,他们将被重定向到特定页面。我怎样才能做到这一点?
hi everyone, I want the user to select an item in a combobox and when they press a button, that they will be redirected to the specific page. How can I achieve this?
<pre><Grid>
<ComboBox x:Name="Campus_Selector" HorizontalAlignment="Center" Margin="0,414,0,0" VerticalAlignment="Top" PlaceholderText="Select a Campus " Width="233">
<ComboBoxItem Content="Auckland Park" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100" />
<ComboBoxItem Content="Bloemfontein" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Boksburg" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Cape Town" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Durban" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Nelspruit" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Polokwane" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Port Elizabeth" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Potchefstroom" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Pretoria" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Roodepoort" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Sandton" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Stellenbosch" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
<ComboBoxItem Content="Vereeniging" HorizontalAlignment="Center" Height="100" Margin="0,0,0,0" VerticalAlignment="Center" Width="100"/>
</ComboBox>
<Button x:Name="Navtocapus" Content="Navigate to selected Campus" HorizontalAlignment="Left" Margin="100,504,0,0" VerticalAlignment="Top" Click="Navtocapus_Click"/>
</Grid>
注意这是UWP
我尝试过:
我尝试使用if语句,然后我尝试了所有的Campus_Selector.Selected(语句),如果这样做,那么
Note this is for UWP
What I have tried:
I tried using an if statement, and I tried all the Campus_Selector.Selected(statements) if that makes sence
推荐答案
ComboBox继承自Selector。
使用SelectedItem属性引用按钮处理程序中当前选定的项目:
Selector.SelectedItem属性(Windows.UI.Xaml.Controls.Primitives) - UWP app developer | Microsoft Docs [ ^ ]
您需要确保物品实际被选中;否则你会崩溃。
ComboBox inherits from Selector.
Use the SelectedItem property to reference the currently selected item in the button handler:
Selector.SelectedItem Property (Windows.UI.Xaml.Controls.Primitives) - UWP app developer | Microsoft Docs[^]
You need to insure an item is actually selected; else you will crash.
这篇关于按钮单击UWP时,使用选中的组合框项目导航到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文