how to select dropdown menu item and navigate

shreshta valluru 86 Reputation points
2022-11-15T13:13:37.577+00:00

In login form, need a dropdown menu items and select any item navigate to that item form in wpf

Developer technologies Windows Forms
Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2022-11-16T03:19:25.187+00:00

    Hi, @shreshta valluru . You could try to refer to the code below.
    Xaml:

            <StackPanel>  
                    <Menu>  
                        <MenuItem Name="Menu1" Header="File" >  
                            <MenuItem Name="Menu11" Header="New"/>  
                        </MenuItem>  
                        <MenuItem Name="Menu2" Header="Tools">  
                            <MenuItem Name="Menu21" Header="Theme" Click="Menu21_Click"/>  
                            <MenuItem Click="Menu22_Click" Name="Menu22" Header="Customize"/>  
                            <MenuItem   Name="Menu23" Header="Options"/>  
                        </MenuItem>  
                    </Menu>  
        <Border BorderThickness="2" BorderBrush="Gray" Width="800" Height="350" >   
      < Frame Name = " mainFrame " / >  
    </Border>  
               </StackPanel>  
    

    Codebehind:

    using System.Windows;  
    using System.Windows.Forms.Integration;  
    using Forms1;  
         private void Menu22_Click(object sender, RoutedEventArgs e)  
                {  
                    mainFrame.NavigationService.Navigate(new CustomizePage());  
                }  
                 private void Menu21_Click(object sender, RoutedEventArgs e)  
            {  
                Form1 form1 = new Form1();  
                form1.TopLevel = false;  
                WindowsFormsHost host = new WindowsFormsHost();  
                host.Child=form1;  
                mainFrame.NavigationService.Navigate(host);  
            }  
    

    CustomizePage:

    <Grid Background="AliceBlue">  
            <TextBlock Text="Customize Page"/>  
        </Grid>  
    

    ThemePage:
    260782-image.png

    Project structure:

    260737-image.png

    The result:
    260714-9.gif

    ----------------------------------------------------------------------------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.