码迷,mamicode.com
首页 > Windows程序 > 详细

WPF Datagrid 控制 第一行和第一列之间的空白

时间:2019-12-21 00:43:17      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:复制   bar   blog   http   title   tst   ring   def   off   

原文:WPF Datagrid 控制 第一行和第一列之间的空白

这个位置就是 这里

技术图片

我们更改 DataGridControltemplate 模板

看树形结构 里面是一个BUtton

功能是全选 能找到了 那就直接改掉就可以

 

  1. <ControlTemplate x:Key="DataGridControlTemplate1" TargetType="{x:Type DataGrid}">
  2. <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
  3. <ScrollViewer x:Name="DG_ScrollViewer" Focusable="False">
  4. <ScrollViewer.Template>
  5. <ControlTemplate TargetType="{x:Type ScrollViewer}">
  6. <Grid>
  7. <Grid.ColumnDefinitions>
  8. <ColumnDefinition Width="Auto"/>
  9. <ColumnDefinition Width="*"/>
  10. <ColumnDefinition Width="Auto"/>
  11. </Grid.ColumnDefinitions>
  12. <Grid.RowDefinitions>
  13. <RowDefinition Height="Auto"/>
  14. <RowDefinition Height="*"/>
  15. <RowDefinition Height="Auto"/>
  16. </Grid.RowDefinitions>
  17. <Button Width="208" Height="125.917" Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}">
  18. <Button.Visibility>
  19. <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
  20. <Binding.ConverterParameter>
  21. <DataGridHeadersVisibility>All</DataGridHeadersVisibility>
  22. </Binding.ConverterParameter>
  23. </Binding>
  24. </Button.Visibility>
  25. </Button>
  26. <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1">
  27. <DataGridColumnHeadersPresenter.Visibility>
  28. <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
  29. <Binding.ConverterParameter>
  30. <DataGridHeadersVisibility>Column</DataGridHeadersVisibility>
  31. </Binding.ConverterParameter>
  32. </Binding>
  33. </DataGridColumnHeadersPresenter.Visibility>
  34. </DataGridColumnHeadersPresenter>
  35. <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"/>
  36. <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}"/>
  37. <Grid Grid.Column="1" Grid.Row="2">
  38. <Grid.ColumnDefinitions>
  39. <ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}}"/>
  40. <ColumnDefinition Width="*"/>
  41. </Grid.ColumnDefinitions>
  42. <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}"/>
  43. </Grid>
  44. </Grid>
  45. </ControlTemplate>
  46. </ScrollViewer.Template>
  47. <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  48. </ScrollViewer>
  49. </Border>
  50. </ControlTemplate>

 

改这个就可以

  1. <Button Width="208" Height="125.917" Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}">
  2. <Button.Visibility>
  3. <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
  4. <Binding.ConverterParameter>
  5. <DataGridHeadersVisibility>All</DataGridHeadersVisibility>
  6. </Binding.ConverterParameter>
  7. </Binding>
  8. </Button.Visibility>
  9. </Button>

技术图片

WPF Datagrid 控制 第一行和第一列之间的空白

标签:复制   bar   blog   http   title   tst   ring   def   off   

原文地址:https://www.cnblogs.com/lonelyxmas/p/12075413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!