2 jaremy short Jaremy_Short 于 2015.07.01 14:52 提问

WPF DataGrid列标题重新Template模板 无法使用标题宽度左右拖动

RT 在重写Template后就无法拖动 请问有什么解决办法?

3个回答

taomanman
taomanman   Rxr 2015.07.14 21:00

是不是你为DataGrid设置的样式中已经设定为不能拖动列宽度了吧?

taomanman
taomanman   Rxr 2015.07.14 21:01
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GridViewColumnHeader}"> <Grid> <toolkit:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}" x:Name="dgHeaderBorder" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" IsPressed="{TemplateBinding IsPressed}" IsHovered="{TemplateBinding IsMouseOver}" Padding="{TemplateBinding Padding}" > <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="4,0,4,0"/> </toolkit:DataGridHeaderBorder> <!--Style="{DynamicResource ColumnHeaderGripperStyle}"--> <Thumb x:Name="**PART_HeaderGripper**" Cursor="SizeWE" HorizontalAlignment="Right" Background="{DynamicResource {ComponentResourceKey localCodes:HedmSkins, WindowButtonPenColor}}" Width="1" Height="15" VerticalAlignment="Center" > <Thumb.BitmapEffect> <DropShadowBitmapEffect Color="#000" Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3" /> </Thumb.BitmapEffect> </Thumb> </Grid> </ControlTemplate> </Setter.Value> </Setter>
taomanman
taomanman   Rxr 2015.07.14 21:04
  <Style TargetType="{x:Type GridViewColumnHeader}">
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                     <Grid>
                         <toolkit:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}"
                                                       x:Name="dgHeaderBorder"
                                                     BorderThickness="{TemplateBinding BorderThickness}" 
                                                     Background="{TemplateBinding Background}" 
                                                     IsPressed="{TemplateBinding IsPressed}" 
                                                     IsHovered="{TemplateBinding IsMouseOver}"
                                                     Padding="{TemplateBinding Padding}" >
                             <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                             SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                             VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                               Margin="4,0,4,0"/>
                         </toolkit:DataGridHeaderBorder>

                        <!--Style="{DynamicResource ColumnHeaderGripperStyle}"-->
                         <Thumb x:Name="**PART_HeaderGripper**"
                                Cursor="SizeWE" 
                             HorizontalAlignment="Right" 
                             Background="{DynamicResource {ComponentResourceKey localCodes:HedmSkins, WindowButtonPenColor}}" 
                                Width="1"
                                Height="15"
                                VerticalAlignment="Center" >
                             <Thumb.BitmapEffect>
                                 <DropShadowBitmapEffect Color="#000"
                                                         Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3" />
                             </Thumb.BitmapEffect>
                         </Thumb>
                     </Grid>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>

Csdn user default icon
上传中...
上传图片
插入图片