The width of the binding of the UI element to the width of another interface element

I wanted to associate Widtha column header with the Widthspecified header. However, the code does not work. If I specify explicitly Width(Width = "100"), it works fine. Can someone shed some light and tell me what is wrong with the code below?

<dataGrid:DataGridTemplateColumn x:Name="pdpCol" Width="100">
        <dataGrid:DataGridTemplateColumn.Header>
            <Grid HorizontalAlignment="Stretch">
                <TextBlock Text="PDP" VerticalAlignment="Center" HorizontalAlignment="Center" 
                    TextWrapping="Wrap" Width="{Binding ElementName=pdpCol,Path=ActualWidth }" TextAlignment="Center" />
            </Grid>
        </dataGrid:DataGridTemplateColumn.Header>
</dataGrid:DataGridTemplateColumn>
+3
source share
3 answers

HorizontalAlignment="Center" TextBlock Stretch. TextBlock . , , , TextBlock. HeaderTemplate, .

<dataGrid:DataGridTemplateColumn x:Name="pdpCol" Width="100" Header="PDP">
    <dataGrid:DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" TextAlign="Center" />
        </DataTemplate>
    </dataGrid:DataGridTemplateColumn.HeaderTemplate>
</dataGrid:DataGridTemplateColumn>

,

+4

. HeaderStyle, HeaderTemplate, Header="PDP".

<dataGrid:DataGridTemplateColumn x:Name="pdpCol" Width="100" Header="PDP">
    <dataGrid:DataGridTemplateColumn.HeaderStyle>
         <Style TargetType="{x:Type Primitives:DataGridColumnHeader}">
              <Setter Property="HorizontalContentAlignment" Value="Stretch" />
              <Setter Property="VerticalContentAlignment" Value="Center" />
         </Style>
    </dataGrid:DataGridTemplateColumn.HeaderStyle>
    <dataGrid:DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" TextAlignment="Center" />
        </DataTemplate>
    </dataGrid:DataGridTemplateColumn.HeaderTemplate>
</dataGrid:DataGridTemplateColumn>
+1

, ActualWidth, , , Path=Width.

0

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


All Articles