我有自定义样式的DataGrid,我在重新调整列大小时遇到了麻烦,因为只有当光标在两列之间完全匹配时它才有效
以下是设置DataGridColumnHeader
的样式部分 <Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontFamily" Value="Segoue UI"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="#6b6b6b">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:2)
像这样增加Thumb的宽度:
<Thumb x:Name="PART_RightHeaderGripper" Width="100" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}"/>
答案 1 :(得分:0)
您也可以在运行时更改它。这是一个例子
grd.Columns[1].Width =new DataGridLength(60);
提及指数