Reputation: 6786
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.
Upvotes: 0
Views: 781
Reputation: 6786
Apparently I needed to actually override MeasureOverride
on my custom control class. Oops!
Upvotes: 0
Reputation: 31813
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.
Upvotes: 2