Exemple #1
0
        /// <summary>
        /// Used when a page is leaved to detach webview elements
        /// </summary>
        /// <param name="e">Argument of the navigation event</param>
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            RunOnUI(() =>
            {
                /* Remove notification from grid */
                if (mCapptainGrid.Children.Contains(mNotification))
                {
                    mNotification.UnsetHandler();
                    mCapptainGrid.Children.Remove(mNotification);
                }

                /* Remove notification from grid */
                if (mCapptainGrid.Children.Contains(mAnnouncement))
                {
                    mAnnouncement.UnsetHandler();
                    mCapptainGrid.Children.Remove(mAnnouncement);
                }

                /* Forward navigation event */
                base.OnNavigatedFrom(e);
            });
        }
Exemple #2
0
        /// <summary>
        /// Initialize overlay on the current page
        /// </summary>
        public void InitOverlay()
        {
            /* We have to use RunOnUI to ensure to be in the same thread pool than UI */
      #pragma warning disable 4014
            RunOnUI(() =>
            {
                /* capptainGrid is locked to ensure fast switching between page doesn't crash the app */
                lock (thisLock)
                {
                    mCapptainGrid = new Grid();

                    /* Check if customer have tagged a grid with "capptainGrid" */
                    mCapptainGrid = FindChildControl <Grid>(Window.Current.Content, "CapptainGrid") as Grid;

                    /* Pick the first grid element founded */
                    if (mCapptainGrid == null)
                    {
                        mCapptainGrid = FindChildControl <Grid>(Window.Current.Content, "") as Grid;
                    }

                    /* Take the instance of capptain UI element to add them on capptain grid */
                    mNotification = CapptainOverlayNotification.Instance;
                    mAnnouncement = CapptainOverlayAnnoucement.Instance;

                    /* If we have a grid then insert the overlay in it */
                    if (mCapptainGrid != null)
                    {
                        /* Check that notification is not already set */
                        if (!mCapptainGrid.Children.Contains(mNotification))
                        {
                            /* Add it */
                            try
                            {
                                mCapptainGrid.Children.Add(mNotification);
                            }
                            catch (Exception)
                            {
                                /* Because of threading context we can grab an unexpected error due to webview insertion
                                 * But we have to ensure overlay creation */
                                InitOverlay();
                                return;
                            }


                            /* Set the display_orientation_change event to resize the notification */
                            mNotification.SetHandler();

                            /* Made the first resize to be sure to match the current application size */
                            mNotification.SetWebView();
                        }

                        /* Check an announcement is already set */
                        if (!mCapptainGrid.Children.Contains(mAnnouncement))
                        {
                            /* Add it */
                            try
                            {
                                mCapptainGrid.Children.Add(mAnnouncement);
                            }
                            catch (Exception)
                            {
                                /* Because of threading context we can grab an unexpected error due to webview insertion
                                 * But we have to ensure overlay creation */
                                InitOverlay();
                                return;
                            }

                            /* Set the display_orientation_change event to resize the notification */
                            mAnnouncement.SetHandler();

                            /* Made the first resize to be sure to match the current application size */
                            mAnnouncement.SetWebView();
                        }
                    }
                    else
                    {
                        /* Even if we have locked we ensure that event on overlay are detach  */
                        mNotification.UnsetHandler();
                        mAnnouncement.UnsetHandler();
                        mCapptainGrid = new Grid();

                        /* Run again the init because sometime graphical context isn't set fine */
                        InitOverlay();
                    }
                }
            });
        }