WPF Datagrid 控制 第一行和第一列之间的空白
Posted lonelyxmas
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF Datagrid 控制 第一行和第一列之间的空白相关的知识,希望对你有一定的参考价值。
原文:WPF Datagrid 控制 第一行和第一列之间的空白
这个位置就是 这里
我们更改 DataGridControltemplate 模板
看树形结构 里面是一个BUtton
功能是全选 能找到了 那就直接改掉就可以
- <ControlTemplate x:Key="DataGridControlTemplate1" TargetType="{x:Type DataGrid}">
- <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
- <ScrollViewer x:Name="DG_ScrollViewer" Focusable="False">
- <ScrollViewer.Template>
- <ControlTemplate TargetType="{x:Type ScrollViewer}">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto"/>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <Button Width="208" Height="125.917" Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}">
- <Button.Visibility>
- <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
- <Binding.ConverterParameter>
- <DataGridHeadersVisibility>All</DataGridHeadersVisibility>
- </Binding.ConverterParameter>
- </Binding>
- </Button.Visibility>
- </Button>
- <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1">
- <DataGridColumnHeadersPresenter.Visibility>
- <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
- <Binding.ConverterParameter>
- <DataGridHeadersVisibility>Column</DataGridHeadersVisibility>
- </Binding.ConverterParameter>
- </Binding>
- </DataGridColumnHeadersPresenter.Visibility>
- </DataGridColumnHeadersPresenter>
- <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" Grid.ColumnSpan="2" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Grid.Row="1"/>
- <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="2" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Grid.Row="1" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"/>
- <Grid Grid.Column="1" Grid.Row="2">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}}"/>
- <ColumnDefinition Width="*"/>
- </Grid.ColumnDefinitions>
- <ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
- </Grid>
- </Grid>
- </ControlTemplate>
- </ScrollViewer.Template>
- <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
- </ScrollViewer>
- </Border>
- </ControlTemplate>
改这个就可以
- <Button Width="208" Height="125.917" Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}">
- <Button.Visibility>
- <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
- <Binding.ConverterParameter>
- <DataGridHeadersVisibility>All</DataGridHeadersVisibility>
- </Binding.ConverterParameter>
- </Binding>
- </Button.Visibility>
- </Button>
以上是关于WPF Datagrid 控制 第一行和第一列之间的空白的主要内容,如果未能解决你的问题,请参考以下文章