Width of column header content

Feb 4, 2009 at 7:27 AM
Hello, I've created a DataGrid with a column header consisting of a TextBlock and a TextBox (column name in TextBlock and filter-by-column in TextBox) in a StackPanel. My problem is that the width of the TextBox is set to the width of the TextBlock, not the width of the column (which is wider than the TextBlock). I would like the TextBox to stretch to the width of the column but it seems like the StackPanel is not given the full column width to work with - any ideas on how to make this work? Imagine a "Name" column where the column width is the width of the widest name in the data set, but the filter box is still only as wide as "name".


        <toolkit:DataGrid>
            <toolkit:DataGrid.Resources>
                <Style TargetType="{x:Type primitives:DataGridColumnHeader}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding}"/>
                                    <TextBox />
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </toolkit:DataGrid.Resources>
        </toolkit:DataGrid>
 
Coordinator
Feb 9, 2009 at 6:20 PM
Try this....

        <toolkit:DataGrid>
            <toolkit:DataGrid.Resources>
                <Style TargetType="{x:Type primitives:DataGridColumnHeader}">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding}"/>
                                    <TextBox />
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </toolkit:DataGrid.Resources>
        </toolkit:DataGrid>
Feb 10, 2009 at 9:46 AM
Great! Works perfectly - thanks a lot.