样式Datagrid标题边框问题

时间:2017-12-04 15:41:12

标签: wpf xaml datagrid

我尝试设置datagridcolumn标题的样式,但是在右上角我有一个双边框。

我尝试使用边距,但它不起作用我在运行时总是有这个双边框。

我怎能避免这种情况?

Double border                                                           

<Style TargetType="{x:Type DataGridRow}">
    <Setter Property="Background" Value="{StaticResource BrushAbbGrey255}" />
    <Setter Property="FontFamily" Value="ABBVoice" />
</Style>

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border Padding="7,5,7,4">
                    <ContentPresenter VerticalAlignment="Center"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="Foreground" Value="{StaticResource BrushAbbGrey90}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Border x:Name="BackgroundBorder" 
                            BorderThickness="1,1,1,1" 
                            Margin="-1,0,0,0"
                            Background="{StaticResource BrushAbbGrey240}" 
                            BorderBrush="{StaticResource BrushAbbGrey200}" 
                            Grid.ColumnSpan="2" />
                    <ContentPresenter Margin="8,10,7,10" VerticalAlignment="Center"/>
                    <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" 
                        Grid.Column="1" Width="8" Height="6" Fill="White" Margin="0,0,8,0" 
                        VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                </Grid>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

2 个答案:

答案 0 :(得分:0)

尝试将右边距设置为-1

<Style TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="Foreground" Value="{StaticResource BrushAbbGrey90}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Border x:Name="BackgroundBorder" 
                            BorderThickness="1,1,1,1" 
                            Margin="-1,0,-1,0"
                            Background="{StaticResource BrushAbbGrey240}" 
                            BorderBrush="{StaticResource BrushAbbGrey200}" 
                            Grid.ColumnSpan="2" SnapsToDevicePixels="True" />
                    <ContentPresenter Margin="8,10,7,10" VerticalAlignment="Center"/>
                    <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" 
                        Grid.Column="1" Width="8" Height="6" Fill="White" Margin="0,0,8,0" 
                        VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                </Grid>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

您可能还想将SnapsToDevicePixels的{​​{1}}属性设置为Border

答案 1 :(得分:0)

我为我的数据网格添加了一个样式,将RowHeaderWidth设置为1并且它正常工作。

<Style TargetType="{x:Type DataGrid}">
    <Setter Property="BorderBrush" Value="{StaticResource BrushAbbGrey200}" />
    <Setter Property="HorizontalGridLinesBrush" Value="{StaticResource BrushAbbGrey200}" />
    <Setter Property="VerticalGridLinesBrush" Value="{StaticResource BrushAbbGrey200}" />
    <Setter Property="BorderThickness" Value="1,0" />
    <Setter Property="RowHeaderWidth" Value="1" />
</Style>