I’m trying to bind to the ActualWidth of a column but the binding doesn’t seem to work. In the following example the TextBlock with the binding is always 0 yet the TextBlock updated via code reports the correct number. What’s happening?
XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" Name="MainColumn" />
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="From Binding:" />
<TextBlock Text="{Binding ElementName=MainColumn, Path=ActualWidth}" />
<TextBlock Text="From Code:" />
<TextBlock Text="" Name="WidthFromCodeTextBlock" />
</StackPanel>
<GridSplitter HorizontalAlignment="Right" Width="5" DragDelta="GridSplitter_DragDelta" />
</Grid>
Code:
private void GridSplitter_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
WidthFromCodeTextBlock.Text = MainColumn.ActualWidth.ToString();
}
Not a dependency property, hence no binding updates.
(Also, why do you have columns if you don’t use them?)