0

I have a Win8 app with a custom control, GameView, which I have instantiated three times (as gvMap, gvOurBase, and gvEnemyBase) on my page, and placed into a grid. I need to get the actual size of the control so I can set the RenderTransform and render everything with the proper scaling.

However, whenever I attempt to get the ActualWidth or ActualHeight of my controls, I always get zero. This occurs even if I wait until the page is loaded and call Measure and Arrange on my controls.

How can I get the size of my controls? Or am I not allowed to do this while they are in a grid? Is there another way for me to do the RenderTransform that doesn't rely on the size of the controls? I want each control to show a specific section of the whole game map - gvMap shows the whole map, gvOurBase shows the section of the map that the player has cities, and gvEnemyBase shows the section of the map that the enemy has cities.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
ekolis
  • 6,270
  • 12
  • 50
  • 101
  • For ****'s n giggles, do you try to just grab the value to see it visually to confirm? Like – Chris W. Jan 09 '13 at 23:01
  • I checked in the debugger where I was using the variables; they were indeed zero. I'll look into the ViewBox. – ekolis Jan 11 '13 at 20:16
  • Nope, ViewBox is not what I want - I want to be able to scale only a specific section of the game map to a specific size, not a single control or the entire game map. – ekolis Jan 11 '13 at 20:19

2 Answers2

2

That can happen. I recommend MyControl.RenderSize.Width instead of MyControl.ActualWidth. In layouts that result from dynamic data binding, Actual values aren't always populated.

Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
  • Unfortunately, RenderSize is also (0,0). – ekolis Jan 11 '13 at 20:16
  • Yea RenderSize gives me the correct with but not the correct height. ActualWidth and ActualHeight give also wrong numbers. Listening to the SizeChanged is also wrong size. (I have a grid in a grid) – juFo Oct 10 '16 at 09:49
0

Apparently I needed to actually override MeasureOverride on my custom control class. Oops!

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
ekolis
  • 6,270
  • 12
  • 50
  • 101
  • I also found that setting the RenderTransform of the whole control wouldn't work, since that would let it overlap other controls. I had to do the scaling inside the control's own rendering logic. – ekolis Jan 11 '13 at 21:13