Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:44:38+00:00 2026-06-01T12:44:38+00:00

I spent a good deal of time looking through StackOverflow, as well as Google,

  • 0

I spent a good deal of time looking through StackOverflow, as well as Google, before asking this question, and couldn’t find anything terribly useful. I’m looking for a guideline on how to load a Menu from a compiled Xaml file, and attach it to a Menu control. I’m a WPF newbie, so please bear with me.

In my page, I have the following Xaml:

<Menu ItemsSource="{Binding MainMenu}">
</Menu>

My view model class currently looks like so:

public class MainWindowViewModel : ViewModelBase
{
    public ItemCollection MainMenu { get; set; }

    public MainWindowViewModel()
    {
        Menu m = (Menu)Application.LoadComponent(new Uri("/Assets/Menus/StartupShellMenu.xaml", UriKind.Relative));
        MainMenu = m.Items;
    }
}

The StartupShellMenu.xaml file looks like so:

<Menu xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <MenuItem Header="_File">
        <MenuItem Header="_Open">
            <MenuItem.Icon>
                <Image Height="16" Width="16" Source="/Assets/Icons/Open.png"/>
            </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="E_xit"/>
    </MenuItem>
</Menu>

What I’m seeing is that my menu items show up, but as soon as my mouse moves off the menu (I don’t have to click), the menu disappears. Also, the normal keyboard functionality isn’t working; pressing Alt+F doesn’t display the menu, and once shown, the up/down keys don’t work. I’ve tried changing the type of the MainMenu property to an ObservableCollection, but no change. Any thoughts? I’m sure I’m missing something stupid obvious, but I can’t find anything useful in my searches.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:44:39+00:00Added an answer on June 1, 2026 at 12:44 pm

    This feels like 100% View to me and the ViewModel maybe shouldn’t be involved.

    Why are you using the ViewModel at all for this? Are you really allowing for the Menu to be altered at runtime so it is a dynamic menu?

    If not, then give the class in your StartupShellMenu.xaml file a class name and then load it.

    <Menu x:Class="StartupShellMenu"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <MenuItem Header="_File">
            <MenuItem Header="_Open">
                <MenuItem.Icon>
                    <Image Height="16" Width="16" Source="/Assets/Icons/Open.png"/>
                </MenuItem.Icon>
            </MenuItem>
            <Separator/>
            <MenuItem Header="E_xit"/>
        </MenuItem>
    </Menu>
    

    Then pull it from the ViewModel as it won’t be needed there.

    And instead of putting a Menu in your XAML and binding to MainMenu, just add your new StartupShellMenu class directly in the XAML.

    <local:StartupShellMenu ItemsSource="{Binding MainMenu}" />
    

    If the menu only exists in the View, keep all Menu code 100% in the View.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

apologies if this is redundant, I spent a good deal of time trying to
I've spent a good amount of time coming up with solution to this problem,
I haven't spent a ton of time researching this yet, mostly looking for best
I am new to git but have spent a good deal of time reading
We are looking to replace our usage of Authorize.net. I've spent a good deal
Spent the good part of this morning working through this, but still…. apologies if
I've recently spent a good deal of time performing detailed UML designs of various
Folks, I just spent a good amount of time trying to look this up
I just spent a good deal of time trying to debug a controller action
So, I've spent a good amount of time using ContinuousLinq to bind collections to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.