我开发了一个具有全屏功能的WPF
应用程序。但是当我的窗口处于全屏模式时,只要我右键单击Datagrid
(同时拥有Datagrid
)自定义,Window State Full Screen
中的自定义上下文菜单就无法正常工作上下文在几分之一秒内消失,默认上下文菜单如下所示,显示在Datagrid
上。
____________
| Restore |
| |
| Move |
| |
| Size |
| |
| Minimize |
| |
| Maximize |
| |
| Close |
|__________|
所以,我希望在我的窗口处于全屏模式时隐藏此菜单。 context menu
适用于Maximize
和Normal
窗口状态。
代码段:
<Menu DockPanel.Dock="Top" Height="30" HorizontalAlignment="Stretch">
<MenuItem Header="_View">
<MenuItem IsCheckable="True" IsChecked="False" Header="Full Screen" Checked="FullScreen_Checked" Unchecked="FullScreen_Unchecked"></MenuItem>
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="View Help">
<MenuItem.Icon>
<Image Height="16" Width="16" Source="Resources/question-icon.png"></Image>
</MenuItem.Icon>
</MenuItem>
<Separator></Separator>
<MenuItem Header="About" Click="About_Click">
<MenuItem.Icon>
<Image Height="16" Width="16" Source="Resources/info6.png"></Image>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
<DataGrid Padding="3" BorderBrush="SkyBlue" BorderThickness="1" ItemsSource="{Binding Source={StaticResource cvsCoreData}}" SelectionUnit="FullRow" IsReadOnly="True" Style="{StaticResource AzureDataGrid}" AutoGenerateColumns="False" x:Name="Data" Margin="0,5,0,28">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem x:Name="ContextKeyTerm" IsEnabled="False" IsCheckable="True" IsChecked="True" Header="Key Term" Unchecked="ContextMenu_Unchecked" Checked="ContextMenu_Checked" Tag="0" />
<MenuItem x:Name="ContextKeyTermDescription" IsCheckable="True" IsChecked="True" Header="Key Term Description" Unchecked="ContextMenu_Unchecked" Checked="ContextMenu_Checked" Tag="1" />
<MenuItem x:Name="ContextShortHand" IsCheckable="True" IsChecked="True" Header="Short Hand" Unchecked="ContextMenu_Unchecked" Checked="ContextMenu_Checked" Tag="2" />
<MenuItem x:Name="ContextRule" IsCheckable="True" IsChecked="True" Header="Rule" Unchecked="ContextMenu_Unchecked" Checked="ContextMenu_Checked" Tag="3" />
<MenuItem x:Name="ContextPartM" IsCheckable="True" Header="Part" Unchecked="ContextMenu_Unchecked" Checked="ContextMenu_Checked" Tag="4" />
<MenuItem x:Name="ContextSectionM" IsCheckable="True" Header="Section" Unchecked="ContextMenu_Unchecked" Checked="ContextMenu_Checked" Tag="5" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
private void FullScreen_Checked(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Normal;
this.IgnoreTaskbarOnMaximize = true;
this.WindowState = WindowState.Maximized;
this.ShowTitleBar = false;
}
private void FullScreen_Unchecked(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Normal;
this.IgnoreTaskbarOnMaximize = false;
this.WindowState = WindowState.Maximized;
this.ShowTitleBar = true;
}