C# WPF DataGrid统一列大小缩减

7uzetpgm  于 2023-05-19  发布在  C#
关注(0)|答案(1)|浏览(178)

有必要通过拖动右边缘来均匀地减小列的大小,因为它是在Visual Studio中实现的。
如何通过拖动右边框来统一调整表格的大小?
下面是如何在Visual Studio中调整大小的示例。
变更前:

变更后:

已尝试调整DataGrid设置,但没有帮助

<DataGrid 
      x:Name="MainDataGridDop"  
      IsEnabled="{Binding AppUnlocked}"
      SelectionMode="Single"
      GridLinesVisibility="All"
      HorizontalGridLinesBrush="LightGray"
      VerticalGridLinesBrush="LightGray"
      AlternationCount="2"
      AutoGenerateColumns="False"
      FrozenColumnCount ="2" 
      CanUserAddRows="False" 
      CanUserSortColumns="False"
      ItemsSource="{Binding AddVolumesServiceList}"
      SelectedValue="{Binding SelectedAddVolumesRow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
      MouseRightButtonDown="MainDataGridDop_MouseRightButtonDown"
      ScrollViewer.CanContentScroll="False" 
      ScrollViewer.VerticalScrollBarVisibility="Auto"
      ScrollViewer.HorizontalScrollBarVisibility="Auto"
      CanUserReorderColumns="False" 
      HorizontalContentAlignment="Stretch"                                         
      VerticalContentAlignment="Stretch" 
      UseLayoutRounding="False"
      BorderBrush="#FFDDDDDD" 
      Background="#FFF9F9F9"
      CanUserResizeColumns="True"
      MinWidth="150" Width="Auto" MinHeight="15" ColumnWidth="*" Margin="0,0,0,1"
>
dba5bblo

dba5bblo1#

应尝试将此属性添加到datagrid中。

CanUserResizeColumns="true"

或者,如果你想为每一列设置一个特定的宽度,只要删除通配符,然后为每一列输入特定的宽度即可。
例如:

ColumnWidth="120,120,50,50,*"

相关问题