Datatemplate style to match Silverlight datgrid column header

I have a style with datatemplate on xaml page as 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 will be applied to the datgrid silverlight column header style. Now I want the glass panel inside the template to be the same as the height and width of the silverlight datgrid header header? so how can this be done?

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

+3
source share
1 answer

Have you tried adjusting the horizontal and vertical alignment properties of the StackPanel? You do not need to bind the Width and Height properties of the parent container at all.

StackPanel , , Border, . . :

<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>
+2

Source: https://habr.com/ru/post/1772793/