Menu Bar in WPF

Amit Patel 126 Reputation points
2021-04-30T01:08:47.473+00:00

I want to create a Menu bar in WFP Form, so that I dont write the same code on every page, How can I do that?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,190 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
560 questions
No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,506 Reputation points
    2021-04-30T05:32:43.683+00:00

    You can create the Meun Bar in a UserControl, then use it the page which need the Meun Bar.
    For example, you can create a UserControl named MyMenuBar like below:

     <DockPanel>  
            <Menu DockPanel.Dock="Top">  
                <MenuItem Header="_File">  
                    <MenuItem Header="_Open"/>  
                    <MenuItem Header="_Close"/>  
                    <MenuItem Header="_Save"/>  
                </MenuItem>  
            </Menu>  
           <StackPanel></StackPanel>  
        </DockPanel>  
    

    Then you can use it in Window1 like below:
    <local:MyMenuBar></local:MyMenuBar>
    The Window1 will show the Meun Bar. Did I misunderstand your question? If I did, could you give me more description of your question for me to anlyze.


    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.

    No comments

1 additional answer

Sort by: Most helpful
  1. Amit Patel 126 Reputation points
    2021-04-30T11:31:00.263+00:00

    Thank You @DaisyTian-MSFT , you have understood my query perfectly and has provided the perfect answer.

    No comments