菜单在WPF中无法正常工作 [英] Menu is not working properly in WPF

查看:92
本文介绍了菜单在WPF中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<Menu Height="30" Name="menu1" VerticalAlignment="Top" BorderThickness="2"
            Foreground="White" FontSize="16" FontWeight="Bold" Margin="-2,-2,0,0" Grid.RowSpan="2" Grid.ColumnSpan="66">
          <Menu.Background>
              <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                  <GradientStop Color="#FF3A60AD" Offset="0.528"/>
                  <GradientStop Color="#FF6A85D8" Offset="0.01"/>
                  <GradientStop Color="#FF3464C4" Offset="1"/>
                  <GradientStop Color="#FF202E7E" Offset="1"/>
              </LinearGradientBrush>
          </Menu.Background>
          <Menu.BitmapEffect>
              <DropShadowBitmapEffect />
          </Menu.BitmapEffect>
          <MenuItem Header="File" IsCheckable="True" Click="MenuItem_Click">
              <MenuItem Header="Open" IsCheckable="true">
                  <MenuItem.ToolTip>
                      <ToolTip>
                          Open a file.
                      </ToolTip>
                  </MenuItem.ToolTip>
              </MenuItem>
              <MenuItem Header="_Close" IsCheckable="true"/>
              <MenuItem Header="_Save" IsCheckable="true"/>

              <Separator/>
              <MenuItem Header="Sub Items">
                  <MenuItem Header="Child1 SubItem" IsCheckable="true"/>
                  <MenuItem Header="Child2 SubItem" IsCheckable="true">
                      <MenuItem Header="GrandChild2 SubItem" IsCheckable="true"/>
                  </MenuItem>
              </MenuItem>

          </MenuItem>
          <MenuItem Header="Settings" IsCheckable="true" Foreground="Orange" FontSize="16" >

          </MenuItem>
          <MenuItem Header="Security" IsCheckable="true" Foreground="White" FontSize="16">

          </MenuItem>
          <MenuItem Header="Database" IsCheckable="true" Foreground="LightGreen" FontSize="16">


          </MenuItem>
      </Menu>



该代码无法正常工作.即,当我单击菜单工具(或任何其他菜单项)时,它只是被选中而没有显示任何子菜单.请有人帮我

在此先感谢



the code do not work as it expected. ie when I click the menu Tools (or any other menu item)it is only getting checked it do not show any submenu. please somebody help me

thanks in advance

推荐答案

问题出在IsCheckable="true"中.如果需要子项,请删除此属性.菜单项可以用作带有可见子项或可检查项的ItemsConrol,不能同时出现.如果您考虑一下,您会发现两者都没有意义.

—SA
The problem is in IsCheckable="true". Remove this attribute if you need child items. A menu item can ether act as a ItemsConrol with visible children or checkable, not both at the same time. If you think about it you will see that doing both things makes no sense.

—SA


这篇关于菜单在WPF中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆