2017-08-28 73 views
0

試圖對我的datagrid列標題進行樣式設置時,遇到兩個問題。DataGridColumnHeader樣式的問題

我想要什麼:我希望我的標題寫在帶有邊框和邊距的邊框中。看到圖片:what I want

我得到:我發現,邊境2頭之間繪製的,再加上我無法擺脫的抓地力(白抓地力,灰色陰影)的影子,像你一樣看到圖片what I get

這裏是我的標題樣式:

<Style TargetType="{x:Type DataGridColumnHeader}"> 
    <Setter Property="VerticalContentAlignment" Value="Center" /> 
    <Setter Property="Height" Value="30" /> 
    <Setter Property="SeparatorBrush" Value="{StaticResource ScbWhite}" /> 
    <Setter Property="FontWeight" Value="Bold" /> 
    <Setter Property="Foreground" Value="{StaticResource ScbBlue1}"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type DataGridColumnHeader}"> 
       <Grid Margin="{TemplateBinding Padding}"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="Auto" /> 
        </Grid.ColumnDefinitions> 
        <Border x:Name="columnHeaderBorder" 
          TextBlock.FontWeight="Bold" 
          TextBlock.Foreground="{StaticResource ScbBlue1}" 
          BorderThickness="2" 
          BorderBrush="{StaticResource ScbBlue1}" 
          Background="{StaticResource ScbWhite}" 
          Width="{TemplateBinding Width}" 
          Margin="3,3,3,3" 
          Padding="3,0,3,0"> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
        </Border> 
        <!--BorderBrush="{Binding VerticalGridLinesBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"--> 
        <Thumb x:Name="PART_RightHeaderGripper" Grid.Column="1" 
          HorizontalAlignment="Right" 
          Width="6" BorderThickness="0" 
          BorderBrush="{StaticResource ScbWhite}" 
          Background="{StaticResource ScbWhite}" 
          Cursor="SizeWE"> 
         <Thumb.BitmapEffect> 
          <DropShadowBitmapEffect Color="Transparent" Opacity="0"/> 
         </Thumb.BitmapEffect> 
        </Thumb> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

請,我能做些什麼來得到我想要的東西?

回答

0

當其他列未覆蓋全寬時,DataGrid會添加空列標題以填充空間。該標題有null內容。我添加了一個ControlTemplate觸發器,使邊框對於沒有內容的標頭透明。

要改變拇指外觀我改變Thumb.Template並使其平坦白色矩形

<Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type DataGridColumnHeader}"> 
      <Grid Margin="{TemplateBinding Padding}"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="*" /> 
        <ColumnDefinition Width="Auto" /> 
       </Grid.ColumnDefinitions> 
       <Border x:Name="columnHeaderBorder" 
         TextBlock.FontWeight="Bold" 
         TextBlock.Foreground="blue" 
         BorderThickness="2" 
         BorderBrush="blue" 
         Background="white" 
         Width="{TemplateBinding Width}" 
         Margin="3,3,3,3" 
         Padding="3,0,3,0"> 
        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
           SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
       </Border> 
       <!--BorderBrush="{Binding VerticalGridLinesBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"--> 
       <Thumb x:Name="PART_RightHeaderGripper" Grid.Column="1" 
         HorizontalAlignment="Right" 
         Width="6" BorderThickness="0" 
         Margin="0,3" 
         BorderBrush="white" 
         Background="white" 
         Cursor="SizeWE"> 
        <Thumb.Template> 
         <ControlTemplate> 
          <Border Background="{TemplateBinding Background}"></Border> 
         </ControlTemplate> 
        </Thumb.Template> 
       </Thumb> 
      </Grid> 
      <ControlTemplate.Triggers> 
       <Trigger Property="Content" Value="{x:Null}"> 
        <!--<Setter Property="BorderBrush" Value="Red" TargetName="columnHeaderBorder"/>--> 
        <Setter Property="BorderBrush" Value="Transparent" TargetName="columnHeaderBorder"/> 
       </Trigger> 
      </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </Setter.Value> 
</Setter> 

//我更換了一些StaticResources在模板中,使我的項目編譯。請將它們還原或僅複製模板的修改部分

+0

此功能完美。萬分感謝! – emiliegue