1

I'm developing metro app using Windows 8 release preview and C#(VS 2012),Is there any way to get Grid width which is set to Auto, Brief: I have StackPanel with a Grid in it with n number of rows and n number of columns(Rows and Columns are generating dynamically). I need to know Grid actual width which is in StackPanel, i tried

 1)var Actualwidth = grid.ActualWidth;            
 2)var Minwidth = grid.MinWidth;
 3)var width = grid.Width;
 4)var Renderwidth = grid.RenderSize.Width;

Where Results comes as follows

1 = 0.0
2 = 0.0
3 = NaN
4 = 0.0

Is there any way to get actual width, Please help me, Thanks in advance

Raj Kumar
  • 736
  • 1
  • 12
  • 31

1 Answers1

6

ActualWidth isn't set until after the control is measured and arranged. Try handling the OnLoaded event and getting the width there. See here for the explanation for wpf (same explanation for winrt). For a windows 8 api see here:

For purposes of ElementName binding, ActualWidth does not post updates when it changes (due to its asynchronous and run-time calculated nature). Do not attempt to use ActualWidth as a binding source for an ElementName binding. If you have a scenario that requires updates based on ActualWidth, use a SizeChanged handler.

Community
  • 1
  • 1
N_A
  • 19,799
  • 4
  • 52
  • 98