Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

HTML
<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>


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
Posted
Updated 17-Aug-18 7:42am

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900