2

For some control layout calculations, I need to know the height of the notification area. Sure, I know that it equals 32 pixels in portrait mode in WP 7/8/8.1, but it's not a good idea to hard code this value for the future releases of the OS. How can I retrieve this value on-the-fly in a Silverlight app?

TecMan
  • 2,743
  • 2
  • 30
  • 64

3 Answers3

1

You cant get Height of notification area by Code.

its Standards are Pre-Defined. System Tray is the small tiny bar across the top of the Phone screen. It displays in Portrait mode. When your application is set in Portrait mode, the height of the System Tray becomes 32 pixel and when the application is set in Landscape mode, the width of the System Tray becomes 72 pixel. This is as per the UI Design Guidelines and Interaction Guideline of Windows Phone 7.

You can get more information here about what is accessible

Amit Bhatiya
  • 2,621
  • 1
  • 12
  • 20
1
double contentScaleFactor = (double)Application.Current.Host.Content.ScaleFactor / 100;
double systemTrayHeight = 32 / contentScaleFactor;

Or 72 for landscape orientation. Phones like the Lumia 1520 scale the app content up, so you have to adjust for it.

RandomEngy
  • 14,931
  • 5
  • 70
  • 113
  • Your answer is correct, but if we talk about the actual height on the screen. I needed the height I can use as the values for the Height/MinHeight/Maxheight properties. I needed to calculate those 32 pixels dynamically because it can be changed in later releases of the OS. In fact, you hard-coded the same 32 pixels in your code. – TecMan Aug 08 '14 at 07:42
  • Our approach to the system tray was to set the opacity to 0 and place a shim at the top of the page, so turning it on and off didn't move content around. With your answer we'd have to set opacity to 1, wait for a layout update, then record the offset and set back to 0. I think the "32" number is not quite as likely to change since that number is DPI-independent. I don't think there's a better way of getting the system tray size (while avoiding a scouting layout pass). – RandomEngy Aug 08 '14 at 16:17
  • In any case, it's an interesting idea "to set opacity to 1, wait for a layout update, then record the offset". Can you show us some working code? How do you wait - using a timer, or another technique? – TecMan Aug 09 '14 at 07:11
  • 1
    Well doing that sounded not great to me. You'd probably subscribe to the SizeChanged event on your root element if you wanted that. – RandomEngy Aug 10 '14 at 14:31
0

Found a workaround. We can determine the vertical offset for the main layout root control (generally a Grid), and it will be the height of the system tray:

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    GeneralTransform gt = LayoutRoot.TransformToVisual(Application.Current.RootVisual as UIElement);
    Point offset = gt.Transform(new Point(0, 0));
    double systemTrayHeight = offset.Y;
}
TecMan
  • 2,743
  • 2
  • 30
  • 64
  • This technique will fail when the page is set to support landscape orientation. As answered by @RandomEngy - hardcoding `32`, `72` and taking the `ScaleFactor` into account would be the best route. – Darius V Mar 09 '15 at 14:26