silverlightwindows-phoneheightsystem-traynotification-area

Retrieve WP system tray (notification area) height


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?


Solution

  • 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;
    }