Here is the code:
<GridViewColumn DisplayMemberBinding="{Binding Path=BookId}" Width="100">
<GridViewColumn.Header>
<Border BorderBrush="Black">
<TextBlock Width="{Binding RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type GridViewColumn}},
Path=Width}" Text="ID">
<TextBlock.ContextMenu>
<ContextMenu>item1</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</Border>
</GridViewColumn.Header>
</GridViewColumn>
Basically what i am trying to do is to make the TextBlock in the header follow the width of the whole column.
It is not working: the textblock's width always matches the text inside. Any ideas?... Thanks in advance!
There are two problems in your code
So your code becomes :
<GridViewColumn
DisplayMemberBinding="{Binding Path=BookId}"
Width="100">
<GridViewColumn.Header>
<Border BorderBrush="Black" >
<TextBlock Text="ID" Width="{Binding RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type GridViewColumnHeader}},
Path=ActualWidth}">
<TextBlock.ContextMenu>
<ContextMenu>item1</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</Border>
</GridViewColumn.Header>
</GridViewColumn>