开发者

XAML Context Menu not closing

开发者 https://www.devze.com 2022-12-10 18:10 出处:网络
I\'ve got a \"popup\" context menu on a lis开发者_如何学JAVAt 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 th

I've got a "popup" context menu on a lis开发者_如何学JAVAt 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">
  <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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消