Binding to ActualWidth property returns 0 at runtime
Posted: 22 Jun 2021, 15:14
Hello,
I am working on a top bar that displays currencies. It should stretch its inner part based on text width, so I used binding to ActualWidth for it to work, which is fine in WPF. But in Unity it always returns 0.
If I did it without setting grid's Width, I had issues that PanelBackground would take more width than the TextBlock itself.
Any ideas how to fix this, or re-structure layout to avoid this type of solution?
I am working on a top bar that displays currencies. It should stretch its inner part based on text width, so I used binding to ActualWidth for it to work, which is fine in WPF. But in Unity it always returns 0.
If I did it without setting grid's Width, I had issues that PanelBackground would take more width than the TextBlock itself.
Code: Select all
<!-- Coins -->
<DockPanel>
<Control Template="{StaticResource IconPlus}" Width="120" Height="120" DockPanel.Dock="Left" Panel.ZIndex="1" />
<Control Template="{StaticResource IconCoin}" Width="120" Height="120" DockPanel.Dock="Right" Panel.ZIndex="1" />
<Grid Width="{Binding Path=ActualWidth, ElementName=CoinsAmount, UpdateSourceTrigger=PropertyChanged}">
<Control Template="{StaticResource DarkPanelBackground}" Margin="-45, 40, -60, 40" />
<TextBlock x:Name="CoinsAmount" Text="8 547" FontSize="36" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" />
</Grid>
</DockPanel>