Modifying GridViewColumn width using converter RRS feed

  • Question

  • Hi All,

    I have a small question.

    I have a StackPanel sitting inside a GridViewColumn.

    Based on some DataContext's property, The controls inside the StackPanel need to be modified. For which, the Width of the StackPanel has to be increased or decreased.

    I'm unable to update the Width using ValueConverter.

    My doubt is can I update the Width of StackPanel during runtime???

    If this is done, I also need to update the GridViewColumn's (parent in this case) width.

    Please help..

    Thanks in advance,

    Sai Kishore.

    Friday, April 26, 2013 5:02 AM


  • Hi, If you set the width to Auto (or not set at all) the width will be set to the contents size so you wont have to do any of this. For example, here in the code below everything is re sized automatically: <DataGrid x:Name="instancesDataGrid" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTemplateColumn Header="Column 1" > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center"> <TextBlock Text="{Binding Name}" /> </StackPanel> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid>

    Please Mark as Answered If this answers your question Or UnMark as Answered if it did not.
    Happy to Help :)
    My Site

    • Proposed as answer by Lisa Zhu Monday, April 29, 2013 8:27 AM
    • Marked as answer by Lisa Zhu Wednesday, May 1, 2013 1:42 PM
    Friday, April 26, 2013 6:30 AM