How to adjust the size of the column in a DataGrid when the content is smaller thant the actual width of the column?
I have a datagrid with a column. I am using a multivalue converter to set the width of the textblock of this column. The converter is this:
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Background" Value="Orange"/>
<Setter Property="Width">
<Setter.Value>
<MultiBinding Converter="{StaticResource MiMultiValueConverter}">
<Binding Path="DataContext.UseConverterIsChecked" Source="{x:Reference ProxyElement}"/>
<Binding Path="DataContext.WidthColumn2" Source="{x:Reference ProxyElement}"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.ElementStyle>
I am setting the backgruond to know if it works or not.
Well, when I set a width bigger than the original width of the column, the column is resized to the size of the content. How ever, if the textblock is resized to a lower value than the actual size of the column, the column is not resize to the context.
The result is this:
Original size of the column:
When I resize to a bigger width:
If I resize to a lower value of the column width:
How could I do that the width of the column adjust to the context?
Thanks.