Пример #1
0
        /// <summary>Raised when the adapter's control has been added to a page and is about to be displayed.</summary>
        /// <param name="sender">The control that raised this event.</param>
        /// <param name="e">Event arguments providing the original source of this event.</param>
        private void OnLoaded(object sender, System.Windows.RoutedEventArgs e)
        {
            // Fetch this control's parent page.
            var parentPage = DotNetPageServices.FetchParentPageFrom(fControl);

            if (parentPage == null)
            {
                return;
            }

            // Do not continue if this control has already been loaded on the page.
            // Note: This can occur if the parent page was unloaded and re-loaded later, which happens when
            //       navigating to another page within the app and then navigating back to the parent page.
            var pageAdapter = fPageProxy.Page as Interop.UI.DotNetPageAdapter;

            if ((pageAdapter != null) && (pageAdapter.Page == parentPage))
            {
                return;
            }

            // Store a reference to the new parent page.
            if (pageAdapter != null)
            {
                pageAdapter.Page = null;
            }
            pageAdapter      = new DotNetPageAdapter();
            pageAdapter.Page = parentPage;
            fPageProxy.Page  = pageAdapter;

            // Relay the event.
            if (this.Loaded != null)
            {
                this.Loaded.Invoke(this, CoronaLabs.WinRT.EmptyEventArgs.Instance);
            }
        }
Пример #2
0
        /// <summary>Raised when the adapter's control has been removed from the page and is no longer visible onscreen.</summary>
        /// <param name="sender">The control that raised this event.</param>
        /// <param name="e">Event arguments providing the original source of this event.</param>
        private void OnUnloaded(object sender, System.Windows.RoutedEventArgs e)
        {
            // Do not continue if this control is still attached to its parent page.
            // This can happen when navigating to another page within the app, where the parent page gets unloaded instead.
            var parentPage = DotNetPageServices.FetchParentPageFrom(fControl);

            if (parentPage != null)
            {
                return;
            }

            // Remove the page reference that the control is no longer attached to.
            var pageAdapter = fPageProxy.Page as Interop.UI.DotNetPageAdapter;

            if (pageAdapter != null)
            {
                pageAdapter.Page = null;
            }
            fPageProxy.Page = null;

            // Relay the event.
            if (this.Unloaded != null)
            {
                this.Unloaded.Invoke(this, CoronaLabs.WinRT.EmptyEventArgs.Instance);
            }
        }