WPF Datagrid template removes ability to resize columns

有些话、适合烂在心里 提交于 2019-12-08 17:38:27

问题


How come whenever I override the default template for a DataGridColumnHeader it can no longer be resized by the user even though CanUserResizeColumns is set to true for the datagrid? Is there something that I need to add to the template to restore this functionality?

Here's my template xaml:

<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridColumnHeader">
                    <Border BorderThickness="1" Margin="-1,0,0,0"  Background="#f9f9f9" BorderBrush="Gray">
                        <Grid>
                            <TextBlock Margin="2" Text="{TemplateBinding  Content}"  VerticalAlignment="Center" 
                                HorizontalAlignment="Left"  TextWrapping="Wrap"/>                           
                        </Grid>
                    </Border>                        
                </ControlTemplate>
            </Setter.Value>
        </Setter>
</Style>

回答1:


Add the Thumb control to the template. You haven't posted template markup code, but you can check this post for complete example.




回答2:


Check out: WPF Toolkit DataGrid, Part II – Custom styling

You can download sample code here to style a DataGridColumnHeader in XAML.



来源:https://stackoverflow.com/questions/3133097/wpf-datagrid-template-removes-ability-to-resize-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!