Hodaya Shalom
Hodaya Shalom

Reputation: 4417

Clicking between columns to fix the size, eliminates my size settings - the WPF DataGrid

I defined in the DataGrid the size of the columns in the following way:

<DataGrid x:Name="DG" ItemsSource="{Binding X}" AutoGenerateColumns="False" ColumnWidth="*">

This works fine until the moment I press between the two columns to see the entire contents of a particular column, then he does not know my definition of this column and increases the column more than necessary by its contents.

Why is this happening and How can prevent it?

Upvotes: 0

Views: 46

Answers (1)

kmatyaszek
kmatyaszek

Reputation: 19296

You can prevent this by using style from this site: http://msdn.microsoft.com/en-us/library/ff506248.aspx and remove from that: PART_LeftHeaderGripper and PART_RightHeaderGripper.

<Window.Resources>
...
<!--Style and template for the DataGridColumnHeader.-->
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Template">
<Setter.Value>
    <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
        <Grid>
            <Border x:Name="columnHeaderBorder"
  BorderThickness="1"
  Padding="3,0,3,0">
                <Border.BorderBrush>
                    <LinearGradientBrush EndPoint="0.5,1"
                   StartPoint="0.5,0">
                        <GradientStop Color="{DynamicResource BorderLightColor}"
              Offset="0" />
                        <GradientStop Color="{DynamicResource BorderDarkColor}"
              Offset="1" />
                    </LinearGradientBrush>
                </Border.BorderBrush>
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1"
                   StartPoint="0.5,0">
                        <GradientStop Color="{DynamicResource ControlLightColor}"
              Offset="0" />
                        <GradientStop Color="{DynamicResource ControlMediumColor}"
              Offset="1" />
                    </LinearGradientBrush>
                </Border.Background>
                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
            </Border>

            <!--<Thumb x:Name="PART_LeftHeaderGripper"
 HorizontalAlignment="Left"
 Style="{StaticResource ColumnHeaderGripperStyle}" />
            <Thumb x:Name="PART_RightHeaderGripper"
 HorizontalAlignment="Right"
 Style="{StaticResource ColumnHeaderGripperStyle}" />-->
        </Grid>
    </ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
    <LinearGradientBrush EndPoint="0.5,1"
           StartPoint="0.5,0">
        <GradientStop Color="{DynamicResource ControlLightColor}"
      Offset="0" />
        <GradientStop Color="{DynamicResource ControlMediumColor}"
      Offset="1" />
    </LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
...
</Window.Resources>

Upvotes: 1

Related Questions