Beispiel #1
0
        private bool CanNavigate(Uri oldValue, Uri newValue, NavigationType navigationType)
        {
            var cancelArgs = new Navigation.NavigatingCancelEventArgs
            {
                Frame  = this,
                Source = newValue,
                IsParentFrameNavigating = true,
                NavigationType          = navigationType,
                Cancel = false,
            };

            OnNavigating(this.Content as IContent, cancelArgs);

            // check if navigation cancelled
            if (cancelArgs.Cancel)
            {
                Debug.WriteLine("Cancelled navigation from '{0}' to '{1}'", oldValue, newValue);

                if (this.Source != oldValue)
                {
                    // enqueue the operation to reset the source back to the old value
                    Dispatcher.BeginInvoke((Action)(() => {
                        this.isResetSource = true;
                        SetCurrentValue(SourceProperty, oldValue);
                        this.isResetSource = false;
                    }));
                }
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private void OnNavigating(IContent content, Navigation.NavigatingCancelEventArgs e)
        {
            // first invoke child frame navigation events
            foreach (var f in GetChildFrames())
            {
                f.OnNavigating(f.Content as IContent, e);
            }

            e.IsParentFrameNavigating = e.Frame != this;

            // invoke IContent.OnNavigating (only if content implements IContent)
            if (content != null)
            {
                content.OnNavigatingFrom(e);
            }

            // raise the Navigating event
            if (Navigating != null)
            {
                Navigating(this, e);
            }
        }