You have the few options you can does this, forcing-to-call and would make all Window.Measure
Window.Arrange
the values to being calculated, or you can GE T those values in the Window.Loaded
event. This same issue are discussed already on this question.
If you is sizing to content:
Window.Measure(new size (doublepositiveinfinity, double positiveinfinitywindow. Arrange (new rect0, 0, Window. Desiredwidth, Window. Desiredheight
If you is using an explicit window size:
window.Measure(new Size(Width, Height));window.Arrange(new Rect(0, 0, window.DesiredWidth, window.DesiredHeight));
Or
public Mywindow () { loaded< Span class= "PLN" > += delegate{ //access actualwidth and ActualHeight here }; }
just had the same issue and Just calling TextBlock. Measure (New Size ());
aint enough. I had to use TextBlock. Measure (New Size (double). PositiveInfinity, double. PositiveInfinity));
to get a result for TextBlock. DesiredSize
The key is to realize that setting it in code like this:
sp2.Margin = new System.Windows.Thickness{ Left = 5 };
is equivalent to:
sp2.Margin = new system. Windows. Thickness{ left = 5, top Span class= "pun" >= 0, Right = 0 bottom = 0 };
Get dimensions before adding to the bounds