views:

150

answers:

1

I've got a "popup" context menu on a list box, and there are two behaviors that would seem "out-of-the-box" but I am having a tough time getting the XAML ContextMenu to behave the way I would expect...

One is that, when I pick a sub-menu (e.g. "One" or "Two"), the initial menu continues to stay open (e.g. "Menu" does not go away once I've made a selection). Second is that the menu margins seem odd. Left justifying Horizontally does not seem to make the main menu (e.g. "Menu") left justify... I can work around this by tweaking the margin - but thats painful for dynamic text..

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
  <StackPanel>
    <ListView>
      <ListView.ContextMenu>
        <!-- StaysOpen="False" -->
        <ContextMenu>
          <!--  Background="Transparent" Margin="-8,0,-8,0" -->
          <Menu>
            <!-- StaysOpenOnClick="False" -->
            <MenuItem Header="Menu">
              <MenuItem Header="One" />
              <MenuItem Header="Two" />
            </MenuItem>
          </Menu>
        </ContextMenu>
      </ListView.ContextMenu>
      <ListViewItem Content="Red" />
      <ListViewItem Content="Orange" />
      <ListViewItem Content="Black" />
      <ListViewItem Content="Blue" />
      <ListViewItem Content="Green" />
    </ListView>
  </StackPanel>
</Page>

Any thoughts on how to make the Main menu of this popup behave? Thanks in advance, T

A: 

Try this:

    <ContextMenu>
      <MenuItem Header="Menu">
        <MenuItem Header="One" />
        <MenuItem Header="Two" />
      </MenuItem>
    </ContextMenu>

you are not supposed to have a menu inside a context menu. you should put menuitem directly.

viky