wpf全屏隐藏菜单

时间:2017-07-12 08:46:32

标签: wpf menu hide fullscreen

我需要隐藏主菜单?当我切换到全屏模式。怎么做? 我有这样的菜单:

   <Menu DockPanel.Dock="Top">
                    <Menu.ItemsPanel>
                        <ItemsPanelTemplate>
                            <DockPanel></DockPanel>
                        </ItemsPanelTemplate>
                    </Menu.ItemsPanel>
                    <MenuItem Header="Файл">
                        <MenuItem Header="Выход" Click="biExit_Click" />
                    </MenuItem>
                    <MenuItem Header="Данные">
                        <MenuItem Header="Импорт" Click="biImportData_ItemClick" />
                        <MenuItem Header="Перестроить кэш" Click="biRebuidCache_ItemClick" />
                    </MenuItem>
                    <MenuItem Header="Режим" x:Name="ModeSelector">
                        <MenuItem Header="Договора" Click="Mode1_Click" />
                        <MenuItem Header="Имущество" Click="Mode2_Click" />
                    </MenuItem>
                </Menu>

我在按键F11上有切换器:

  if (e.Key == Key.F11)
                {
                    if(_fullScreenWindow == null)
                      {
                        MinHeight = MinHeightDefault;
                        MinWidth = MinWidthDefault;
                        MaxHeight = MaxHeightDefault;
                        MaxWidth = MaxWidthDefault;

                        _fullScreenWindow = true;
                        WindowState = WindowState.Maximized;
                        WindowStyle = WindowStyle.None;
                        ResizeMode = ResizeMode.CanResize;
                      }
                      else
                      {
                        WindowState = WindowState.Normal;
                        WindowStyle = WindowStyle.ToolWindow;
                        ResizeMode = ResizeMode.CanResize;
                        _fullScreenWindow = null;
                      }
                }

如果这是一个愚蠢的问题我提前道歉,但我知道如何以正确的方式制作它

1 个答案:

答案 0 :(得分:0)

为您的菜单命名:

<Menu x:Name="MyMenu" DockPanel.Dock="Top">
                <Menu.ItemsPanel>
                    <ItemsPanelTemplate>
                        <DockPanel></DockPanel>
                    </ItemsPanelTemplate>
                </Menu.ItemsPanel>
                <MenuItem Header="Файл">
                    <MenuItem Header="Выход" Click="biExit_Click" />
                </MenuItem>
                <MenuItem Header="Данные">
                    <MenuItem Header="Импорт" Click="biImportData_ItemClick" />
                    <MenuItem Header="Перестроить кэш" Click="biRebuidCache_ItemClick" />
                </MenuItem>
                <MenuItem Header="Режим" x:Name="ModeSelector">
                    <MenuItem Header="Договора" Click="Mode1_Click" />
                    <MenuItem Header="Имущество" Click="Mode2_Click" />
                </MenuItem>
            </Menu>

全屏时隐藏它:

 if (e.Key == Key.F11)
            {
                if(_fullScreenWindow == null)
                  {
                    MinHeight = MinHeightDefault;
                    MinWidth = MinWidthDefault;
                    MaxHeight = MaxHeightDefault;
                    MaxWidth = MaxWidthDefault;

                    _fullScreenWindow = true;
                    WindowState = WindowState.Maximized;
                    WindowStyle = WindowStyle.None;
                    ResizeMode = ResizeMode.CanResize;
                    MyMenu.Visibility = Visibility.Collapsed; //HERE
                  }
                  else
                  {
                    WindowState = WindowState.Normal;
                    WindowStyle = WindowStyle.ToolWindow;
                    ResizeMode = ResizeMode.CanResize;
                    _fullScreenWindow = null;
                    MyMenu.Visibility = Visibility.Visible; //HERE
                  }
            }