应用此样式后,DataGrid ColumnHeader的ContextMenu未显示?

时间:2013-05-19 10:25:19

标签: wpf datagrid styles contextmenu

如果我将此样式应用于WPF DataGrid,则不会显示columnheader的上下文菜单。如果我删除此样式,它会显示出来。这种风格有什么不对或缺失?

<Style x:Key="DefaultColumnHeader"
       TargetType="{x:Type DataGridColumnHeader}">
  <Setter Property="VerticalContentAlignment"
          Value="Center" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
        <dg:DataGridHeaderBorder x:Name="dataGridHeaderBorder"
                                 Margin="-1 0 0 0"
                                 VerticalAlignment="Top"
                                 Height="24"
                                 IsClickable="{TemplateBinding CanUserSort}"
                                 IsHovered="{TemplateBinding IsMouseOver}"
                                 IsPressed="{TemplateBinding IsPressed}"
                                 SeparatorBrush="{TemplateBinding SeparatorBrush}"
                                 SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                                 SortDirection="{TemplateBinding SortDirection}"
                                 Background="{TemplateBinding Background}"
                                 BorderBrush="{TemplateBinding BorderBrush}"
                                 BorderThickness="{TemplateBinding BorderThickness}"
                                 Padding="{TemplateBinding Padding}"
                                 Grid.ColumnSpan="1">
          <Grid x:Name="grid"
                Width="Auto"
                Height="Auto"
                RenderTransformOrigin="0.5,0.5"
                Margin="-5 0 -5 0">
            <Grid.RenderTransform>
              <TransformGroup>
                <ScaleTransform />
                <SkewTransform />
                <RotateTransform />
                <TranslateTransform />
              </TransformGroup>
            </Grid.RenderTransform>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Thumb x:Name="PART_LeftHeaderGripper"
                   Grid.Column="0"
                   HorizontalAlignment="Left"
                   Width="3"
                   BorderThickness="0"
                   Background="Transparent"
                   Cursor="SizeWE"
                   Margin="0"
                   Template="{StaticResource ThumbTemplate}" />
            <ContentPresenter x:Name="contentPresenter"
                              Grid.Column="1"
                              Margin="2 0"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                              ContentStringFormat="{TemplateBinding ContentStringFormat}"
                              ContentTemplate="{TemplateBinding ContentTemplate}">
              <ContentPresenter.Content>
                <Binding RelativeSource="{RelativeSource TemplatedParent}"
                         Path="Content" />
              </ContentPresenter.Content>
            </ContentPresenter>
            <Thumb x:Name="PART_RightHeaderGripper"
                   Grid.Column="2"
                   HorizontalAlignment="Right"
                   Width="3"
                   BorderThickness="0"
                   Background="Transparent"
                   Cursor="SizeWE"
                   Margin="0"
                   Template="{StaticResource ThumbTemplate}" />
          </Grid>
        </dg:DataGridHeaderBorder>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

0 个答案:

没有答案