Gowthaman
Gowthaman

Reputation: 852

Resizing datagrid column with CanUserResize="True" is not working in WPF

I have used the CanUserResize="True" for the datagrid column but i can't able to resize while hover on the column header.

<DataGrid x:Name="ScenarioExecutables" AutoGenerateColumns="False" CanUserAddRows="False" RowHeaderWidth="0" Margin="10" FontSize="14"
                Grid.Row="1" CanUserResizeColumns="True">
    <DataGrid.Columns>
         <DataGridTextColumn Header="Scenario" Width="1*" IsReadOnly="True" CanUserResize="True">
               <DataGridTextColumn.ElementStyle>
                    <Style TargetType="TextBlock">
                        <Setter Property="TextWrapping" Value="Wrap"/>
                    </Style>
               </DataGridTextColumn.ElementStyle>
         </DataGridTextColumn>
          <DataGridTextColumn Header="Description"  Width="2*" CanUserResize="True"/>
    </DataGrid.Columns>
</DataGrid>

Upvotes: 6

Views: 6728

Answers (1)

Gowthaman
Gowthaman

Reputation: 852

Since i had changed the Template of the datagrid column header so the resizing will not working properly

so add this code the resizing will work..

<Thumb x:Name="PART_RightHeaderGripper" Grid.Column="1"
                                        HorizontalAlignment="Right"
                                        Width="2" BorderThickness="1"
                                        BorderBrush="{Binding VerticalGridLinesBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
                                        Cursor="SizeWE"/>

Upvotes: 10

Related Questions