我在右键单击DataGrid时使用ContextMenu。我不想在DataGrid标题上显示ContextMenu。
<dgWPFCtrl:SelfBindingDataGrid Grid.Row="1" Margin="0,5,0,0" Name="_cycleList"
ItemsSource="{Binding Path=CurrentElementsList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="False"
SelectedItem="{Binding Path=CurrentItem}">
<dgWPFCtrl:SelfBindingDataGrid.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding OpenCycleCommand}" Header="CYCLE" CommandParameter="CYCLE"/>
<MenuItem Command="{Binding OpenCycleCommand}" Header="H1" CommandParameter="H1"/>
<MenuItem Command="{Binding OpenCycleCommand}" Header="PDF" CommandParameter="PDF"/>
</ContextMenu>
</dgWPFCtrl:SelfBindingDataGrid.ContextMenu>
我该如何解决这个问题?
答案 0 :(得分:2)
您可以仅使用ColumnHeaderStyle
标题更改ContextMenu:
<dgWPFCtrl:SelfBindingDataGrid>
<dgWPFCtrl:SelfBindingDataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu Visibility="Collapsed" />
</Setter.Value>
</Setter>
</Style>
</dgWPFCtrl:SelfBindingDataGrid.ColumnHeaderStyle>