WPF Datagrid的模板移除调整列大小的能力 [英] WPF Datagrid template removes ability to resize columns

查看:182
本文介绍了WPF Datagrid的模板移除调整列大小的能力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么每当我重写了DataGridColumnHeader它不再即使CanUserResizeColumns设置为true DataGrid的用户调整默认的模板?是否有我需要添加到模板,以恢复此功能的东西吗?

下面是我的模板的XAML:

 <风格X:关键=ColumnHeaderStyle的TargetType ={X:类型DataGridColumnHeader}>
        < setter属性=模板>
            < Setter.Value>
                <的ControlTemplate的TargetType =DataGridColumnHeader>
                    < BORDER了borderThickness =1保证金= -  1,0,0,0背景=#f9f9f9BorderBrush =灰色>
                        <电网>
                            < TextBlock的保证金=2文本={TemplateBinding内容}VerticalAlignment =中心
                                的Horizo​​ntalAlignment =左TextWrapping =自动换行/>
                        < /网格>
                    < /边框>
                < /控件模板>
            < /Setter.Value>
        < /二传手>
< /样式和GT;
 

解决方案

添加<一href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.thumb.aspx">Thumb控制到模板。您还没有公布模板标记code,但你可以检查的这个帖子获取完整的例子。

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>

解决方案

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

这篇关于WPF Datagrid的模板移除调整列大小的能力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆