C#中DataGrid标头列中的无意空间

时间:2015-03-08 11:24:42

标签: c# wpf datagrid

我的DataGrid中最后一个Header列和Header列之间有非常大的空间。空间的背景颜色类似于App背景颜色(#FF454545)。我的标题列的背景颜色是单独设置的。我是否忽略了引起这个问题的事情?

这是我的代码:

<DataGrid Name="dgUserFiles" ItemsSource="{Binding UserFilesObject}" AutoGenerateColumns="False" CanUserAddRows="false">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#FF454545" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
    <DataGrid.Columns>
        <DataGridTextColumn Header="File" Width="3*" Binding="{Binding File}" IsReadOnly="True">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="#FF454545" />
                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn Header="Last Check" Width="2*" Binding="{Binding LastCheck}" IsReadOnly="True">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="#FF454545" />
                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn Header="Next Check" Width="2*" Binding="{Binding NextCheck}" IsReadOnly="True">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="#FF454545" />
                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn Header="Status" Width="1*" Binding="{Binding Status}" IsReadOnly="True">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="#FF454545" />
                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                </Style>
            </DataGridTextColumn.HeaderStyle>
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="Readable">
                            <Setter Property="Foreground" Value="Green"/>
                        </Trigger>
                        <Trigger Property="Text" Value="Not Readable">
                            <Setter Property="Foreground" Value="Red"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTemplateColumn Header="Action" Width="1*">
            <DataGridTemplateColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="#FF454545" />
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                </Style>
            </DataGridTemplateColumn.HeaderStyle>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button Click="btnDgUserFiles_CheckNow_Click">
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Width="12" Height="12" Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_refresh}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </StackPanel>
                        </Button>
                        <Button Click="btnDgUserFiles_Delete_Click">
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Width="12" Height="12" Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_delete}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </StackPanel>
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

这是截图: enter image description here

0 个答案:

没有答案