Ejemplo n.º 1
0
        private void OnNavigating(IContent content, NavigatingCancelEventArgs e)
        {
            // first invoke child frame navigation events
            foreach (var f in GetChildFrames()) {
                f.OnNavigating(f.Content as IContent, e);
            }

            e.IsParentFrameNavigating = !Equals(e.Frame, this);

            // invoke IContent.OnNavigating (only if content implements IContent)
            content?.OnNavigatingFrom(e);

            // raise the Navigating event
            Navigating?.Invoke(this, e);
        }
Ejemplo n.º 2
0
        private bool CanNavigate(Uri oldValue, Uri newValue, NavigationType navigationType)
        {
            var cancelArgs = new NavigatingCancelEventArgs {
                Frame = this,
                Source = newValue,
                IsParentFrameNavigating = true,
                NavigationType = navigationType,
                Cancel = false,
            };
            OnNavigating(Content as IContent, cancelArgs);

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

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

            return true;
        }