question

ComptonAlvaro avatar image
0 Votes"
ComptonAlvaro asked HuiLiu-MSFT commented

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:

143419-imagen.png

When I resize to a bigger width:

143445-imagen.png

If I resize to a lower value of the column width:

143493-imagen.png

How could I do that the width of the column adjust to the context?


Thanks.


windows-wpf
imagen.png (1.8 KiB)
imagen.png (2.0 KiB)
imagen.png (1.7 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ComptonAlvaro .Could you show me your DataContext.UseConverterIsChecked and DataContext.WidthColumn2? How is your x:Reference ProxyElement defined?

0 Votes 0 ·

0 Answers