3
votes

i have a style with datatemplate in xaml page as shown below .

<

    Style x:Name="mytemplate" x:Key="mytemplate"  xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
                                TargetType="dataprimitives:DataGridColumnHeader">
                <Setter Property="ContentTemplate" >
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel Background="Aqua" Height="{Binding this.DataGridColumnHeader.Height}" Width="{Binding this.DataGridColumnHeaderWidth}" >
       <TextBlock Text="{Binding}"   HorizontalAlignment="Center" FontWeight="Black" ></TextBlock>
                                 <TextBox x:Name="{Binding}" Padding="0,-1,0,0"  HorizontalAlignment="Stretch" Width="100" Height="20" KeyDown="txtfilterBox_KeyDown" LostFocus="txtfilterBox_LostFocus" />
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

this style would be applied to the silverlight datgrid column header style. now i want the stackpanel inside the template to be same as the height and width of the silverlight datgrid column header ? so how can that be done?

else how to stretch the content template to fill the whole space of the datagrid column header

1

1 Answers

2
votes

Have you tried setting the StackPanel's horizontal and vertical alignment properties to stretch? You shouldn't need to bind to the Width and Height properties of the parent container at all.

If setting the StackPanel to stretch that doesn't work, simply wrap the stack panel in a Border and you will be golden. See the code below:

<Style x:Name="mytemplate" x:Key="mytemplate"  xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
                                    TargetType="dataprimitives:DataGridColumnHeader">
                    <Setter Property="ContentTemplate" >
                        <Setter.Value>
                            <DataTemplate>
                    <Border Background="Aqua" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                    <StackPanel>
                          <TextBlock Text="{Binding}"   HorizontalAlignment="Center" FontWeight="Black" ></TextBlock>
                                      <TextBox x:Name="{Binding}" Padding="0,-1,0,0"  HorizontalAlignment="Stretch" Width="100" Height="20" KeyDown="txtfilterBox_KeyDown" LostFocus="txtfilterBox_LostFocus" />
                                    </StackPanel>
                    </Border>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>