I am trying to get the inner canvas width and height at runtime, but I always get the same result. Here is my simple code:
MainWindow.xaml:
<Window
...
Title="MainWindow" Height="450" Width="800">
<Grid>
<Viewbox>
<Canvas Width="500" Height="300" Background="Red">
<Canvas Width="200" Height="200" Background="Green" Name="innerCanvas">
</Canvas>
</Canvas>
</Viewbox>
<Button Click="Button_Click" Height="30" VerticalAlignment="Bottom" Content="Click"></Button>
</Grid>
</Window>
MainWindow.cs:
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show($"width: {innerCanvas.ActualWidth}, height: {innerCanvas.ActualHeight}");
}
Despite resizing the window at runtime, the messageBox prints 200x200