I have WrapPanel
defined in XAML:
<ScrollViewer Grid.Column="1" Grid.Row="2">
<WrapPanel x:Name="VideoPanel" >
</WrapPanel>
</ScrollViewer>
And then when I access the size of that WrapPanel
in .cs
Console.WriteLine(VideoPanel.ActualWidth + " x " + VideoPanel.ActualHeight);
Console.WriteLine(VideoPanel.Width + " x " + VideoPanel.Height);
I get the output:
0 x 0
0 x 0
is not a number x is not a number
How to get actual size?
Full XAML:
<Window x:Class="HomeSecurity.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:HomeSecurity"
Title="MainWindow" WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="9*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="1" Grid.Row="2">
<WrapPanel x:Name="VideoPanel" >
</WrapPanel>
</ScrollViewer>
</Grid>
</Window>
Full code:
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
createGUI();
}
private void createGUI() {
AddVideoStream("192.168.0.3");
}
private void AddVideoStream(String sourceIP) {
Console.WriteLine(VideoPanel.ActualWidth + " x " + VideoPanel.ActualHeight);
Console.WriteLine(VideoPanel.Width + " x " + VideoPanel.Height);
}
}
To get actual size you should use
ActualWidth
andActualHeight
properties ofFrameworkElement
but instead of getting them in constructor useFrameworkElement.Loaded
event:and in code