Пример #1
0
        /// <summary>
        /// Called when [back requested] event is fired.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="backRequestedEventArgs">The <see cref="BackRequestedEventArgs"/> instance containing the event data.</param>
        private void OnBackRequested(object sender, BackRequestedEventArgs backRequestedEventArgs)
        {
            if (backRequestedEventArgs.Handled)
            {
                return;
            }

            if (NavigationFrame.CanGoBack)
            {
                backRequestedEventArgs.Handled = true;

                var previousPage = NavigationFrame.BackStack.Last();

                if (previousPage.SourcePageType == typeof(SamplePicker))
                {
                    HideInfoArea();
                }
                else
                {
                    ShowInfoArea();
                }

                NavigationFrame.GoBack();
            }
        }
 public void GoBack()
 {
     if (NavigationFrame.CanGoBack)
     {
         NavigationFrame.GoBack();
     }
 }
Пример #3
0
 private void NavView_BackRequested(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewBackRequestedEventArgs args)
 {
     if (NavigationFrame.CanGoBack)
     {
         NavigationFrame.GoBack();
     }
 }
Пример #4
0
 public void GoBack()
 {
     if (NavigationFrame?.CanGoBack ?? false)
     {
         NavigationFrame.GoBack();
     }
 }
 /// <summary>
 /// Goes backward in the back stack.
 /// </summary>
 public override void GoBack()
 {
     //Navigation is asynchronous so it had to be synchronized or else it would cause problems with an earlier app I was writing.
     navigationLock.WaitOne();
     navigationLock.Reset();
     //This is intentional(?)
     NavigationFrame.GoBack();
 }
Пример #6
0
        private void NavigationView_OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
        {
            if (NavigationFrame.BackStack.LastOrDefault() is PageStackEntry entry)
            {
                NavigationView.SelectedItem = NavigationItems.First(item => item.PageType == entry.SourcePageType).Item;

                NavigationFrame.GoBack();
            }
        }
Пример #7
0
 /// <summary>
 /// Called when [back requested] event is fired.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="backRequestedEventArgs">The <see cref="BackRequestedEventArgs"/> instance containing the event data.</param>
 private void OnBackRequested(object sender, BackRequestedEventArgs backRequestedEventArgs)
 {
     if (NavigationFrame.CanGoBack)
     {
         backRequestedEventArgs.Handled = true;
         HideInfoArea();
         NavigationFrame.GoBack();
     }
 }
 /// <summary>
 /// Go backward in the navigation chain
 /// </summary>
 public bool GoBack()
 {
     Initialize();
     if (!CanGoBack)
     {
         return(false);
     }
     NavigationFrame.GoBack();
     return(true);
 }
Пример #9
0
        /// <summary>
        /// Called when [back requested] event is fired.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="backRequestedEventArgs">The <see cref="BackRequestedEventArgs"/> instance containing the event data.</param>
        private void OnBackRequested(object sender, BackRequestedEventArgs backRequestedEventArgs)
        {
            if (backRequestedEventArgs.Handled)
            {
                return;
            }

            if (NavigationFrame.CanGoBack)
            {
                NavigationFrame.GoBack();
                backRequestedEventArgs.Handled = true;
            }
        }
Пример #10
0
        private void HamburgerMenu_OnItemClick(object sender, ItemClickEventArgs e)
        {
            var category = e.ClickedItem as SampleCategory;

            if (category != null)
            {
                while (NavigationFrame.BackStack.Count > 0)
                {
                    if (NavigationFrame.CanGoBack)
                    {
                        NavigationFrame.GoBack();
                    }
                }
                NavigationFrame.Navigate(typeof(SamplePicker), category);
            }
        }
Пример #11
0
 /// <summary>
 /// KeyDown event
 /// </summary>
 private void CoreWindow_KeyDown(CoreWindow sender, KeyEventArgs args)
 {
     if (args.VirtualKey == Windows.System.VirtualKey.Back)
     {
         Object f = Windows.UI.Xaml.Input.FocusManager.GetFocusedElement();
         if (f != null)
         {
             if (NavigationFrame.CanGoBack)
             {
                 if (f.GetType() == typeof(Windows.UI.Xaml.Controls.TextBox))
                 {
                     return;
                 }
                 NavigationFrame.GoBack();
             }
         }
     }
 }
Пример #12
0
        /// <summary>
        /// Called when [back requested] event is fired.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="backRequestedEventArgs">The <see cref="BackRequestedEventArgs"/> instance containing the event data.</param>
        private void OnBackRequested(object sender, BackRequestedEventArgs backRequestedEventArgs)
        {
            if (backRequestedEventArgs.Handled)
            {
                return;
            }

            if (NavigationFrame.CanGoBack)
            {
                backRequestedEventArgs.Handled = true;
                NavigationFrame.GoBack();
            }
            else
            {
                // To prevent the user from leaving the application
                // with a back key stroke
                backRequestedEventArgs.Handled = true;
            }
        }
Пример #13
0
        /// <summary>
        /// Called when [back requested] event is fired.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="backRequestedEventArgs">The <see cref="BackRequestedEventArgs"/> instance containing the event data.</param>
        private void OnBackRequested(object sender, BackRequestedEventArgs backRequestedEventArgs)
        {
            if (backRequestedEventArgs.Handled)
            {
                return;
            }

            if (SamplePickerGrid.Visibility == Visibility.Visible)
            {
                HideSamplePicker();
                backRequestedEventArgs.Handled = true;
            }
            else if (NavigationFrame.CanGoBack)
            {
                NavigationFrame.GoBack();

                HideSamplePicker();
                backRequestedEventArgs.Handled = true;
            }
        }
Пример #14
0
        private void Animation_Completed(object sender, EventArgs e)
        {
            switch (navArgs.NavigationMode)
            {
            case NavigationMode.New:
                if (navArgs.Uri == null)
                {
                    NavigationFrame.Navigate(navArgs.Content);
                }
                else
                {
                    NavigationFrame.Navigate(navArgs.Uri);
                }
                break;

            case NavigationMode.Back:
                NavigationFrame.GoBack();
                break;

            case NavigationMode.Forward:
                NavigationFrame.GoBack();
                break;

            case NavigationMode.Refresh:
                NavigationFrame.GoBack();
                break;

            default:
                break;
            }

            inNavigation = false;

            DoubleAnimation animation = new DoubleAnimation();

            animation.From     = 0f;
            animation.To       = 1f;
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(200));
            NavigationFrame.BeginAnimation(OpacityProperty, animation);
        }
Пример #15
0
 public override void Execute(object parameter) => NavigationFrame.GoBack();
Пример #16
0
 /// <summary>
 ///		Navigate to the last page.
 /// </summary>
 public void GoBack()
 {
     NavigationFrame.GoBack();
 }
Пример #17
0
        private async void ApplicationBase_Startup(object sender, StartupEventArgs e)
        {
            if (this.isInitialized)
            {
                return;
            }

            this.isInitialized = true;

            if (e.Args != null && e.Args.Length > 0 && e.Args[0] == "registerUriScheme")
            {
                try
                {
                    RegisterUrlProtocols();
                }
                catch
                {
                    // don't show anything... This will only annoy users
                }

                this.Shutdown();
                return;
            }

            ParamPassing.Configure(e.Args, x =>
            {
                x.IsSingleInstance     = this.IsSingleInstance;
                x.BringToFront         = this.ShouldBringToFront;
                x.RandomSelectInstance = true;
                x.DataSeparator        = '\n';

                x.ParameterPassedCallback = new Action <string[]>(args =>
                {
                    if (args != null && args.Length > 0 && args[0].IndexOf(':') > 0 &&
                        ApplicationUrlProtocols.Contains(args[0].Split(':').First(),
                                                         new DynamicEqualityComparer <string>((a, b) => string.Equals(a, b, StringComparison.CurrentCultureIgnoreCase))))
                    {
                        try
                        {
                            this.OnActivationProtocol(new Uri(args[0]));
                        }
                        catch
                        {
                            // if the application recieves malformed or bad urls... We should just ignore it here
                        }
                    }
                    else
                    {
                        this.OnActivated(args);
                    }
                });

                x.ExitDelegate = () =>
                {
                    this.Shutdown();
                    Environment.Exit(0);
                };
            });

            if (this.IsSingleInstance && ParamPassing.AreOtherInstanceActive)
            {
                if (ParamPassing.BringToFront())
                {
                    this.Shutdown();
                }
            }
            else
            {
                if (this.IsSinglePage)
                {
                    WindowType windowType = null;
                    var        window     = Common.CreateWindow(ref windowType);

                    window.ContentTemplateSelector = new CauldronTemplateSelector();

                    window.MinHeight             = 353;
                    window.MinWidth              = 502;
                    window.ShowInTaskbar         = true;
                    window.Topmost               = false;
                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                    window.WindowState           = WindowState.Normal;
                    window.Icon = await UnsafeNative.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location).ToBitmapImageAsync();

                    window.Title = ApplicationInfo.ApplicationName;

                    PersistentWindowInformation.Load(window, this.GetType());

                    window.SizeChanged += (s, e1) =>
                    {
                        if (window.WindowState == WindowState.Normal)
                        {
                            PersistentWindowProperties.SetHeight(window, e1.NewSize.Height);
                            PersistentWindowProperties.SetWidth(window, e1.NewSize.Width);
                        }
                    };
                    window.Closing += (s, e1) => PersistentWindowInformation.Save(window, this.GetType());

                    window.Show();

                    window.Content = this;
                    window.Activate();
                    await this.OnPreload();

                    var rootFrame = new NavigationFrame();
                    rootFrame.DataContext = this;
                    window.Content        = rootFrame;
                    window.InputBindings.Add(new KeyBinding(new RelayCommand(async() => { await rootFrame.GoBack(); }, () => rootFrame.CanGoBack), Key.Back, ModifierKeys.None));
                }
                else if (this.GetType().GetCustomAttribute <ViewAttribute>() != null || Application.Current.Resources.Contains($"View_{this.GetType().Name}"))
                {
                    var oldShutdownMode = Application.Current.ShutdownMode;
                    Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    this.Navigator.As <Navigator>()?.NavigateInternal <ApplicationBase>(this, null, null);
                    await this.OnPreload();

                    if (Application.Current.MainWindow == null)
                    {
                        Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                        Application.Current.Shutdown();
                        return;
                    }

                    Application.Current.MainWindow.Activate();
                    this.Navigator.TryClose(this);
                    Application.Current.ShutdownMode = oldShutdownMode;
                }

                Application.Current.MainWindow = null;
                await this.OnStartup(new LaunchActivatedEventArgs(e.Args));

                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.AddHookParameterPassing();
                    Application.Current.MainWindow.Activate();
                }
            }
        }
Пример #18
0
        private async void ApplicationBase_Startup(object sender, StartupEventArgs e)
        {
            this.isInitialized = true;

            ParamPassing.Configure(e.Args, x =>
            {
                x.IsSingleInstance     = this.IsSingleInstance;
                x.BringToFront         = this.ShouldBringToFront;
                x.RandomSelectInstance = true;
                x.DataSeparator        = '\n';

                x.ParameterPassedCallback = new Action <string[]>(args => this.OnActivated(args));

                x.ExitDelegate = () =>
                {
                    this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    this.Shutdown();
                };
            });

            if (this.IsSingleInstance && ParamPassing.AreOtherInstanceActive)
            {
                if (ParamPassing.BringToFront())
                {
                    this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    this.Shutdown();
                }
            }
            else
            {
                if (this.IsSinglePage)
                {
                    WindowType windowType = null;
                    var        window     = Common.CreateWindow(ref windowType);

                    window.ContentTemplateSelector = new CauldronTemplateSelector();

                    window.MinHeight             = 353;
                    window.MinWidth              = 502;
                    window.ShowInTaskbar         = true;
                    window.Topmost               = false;
                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                    window.WindowState           = WindowState.Normal;
                    window.Icon = await UnsafeNative.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location).ToBitmapImageAsync();

                    window.Title = ApplicationInfo.ApplicationName;

                    PersistentWindowInformation.Load(window, this.GetType());

                    window.SizeChanged += (s, e1) =>
                    {
                        if (window.WindowState == WindowState.Normal)
                        {
                            PersistentWindowProperties.SetHeight(window, e1.NewSize.Height);
                            PersistentWindowProperties.SetWidth(window, e1.NewSize.Width);
                        }
                    };
                    window.Closing += (s, e1) => PersistentWindowInformation.Save(window, this.GetType());

                    window.Show();

                    window.Content = this;
                    window.Activate();
                    await this.OnPreload();

                    var rootFrame = new NavigationFrame();
                    rootFrame.DataContext = this;
                    window.Content        = rootFrame;
                    window.InputBindings.Add(new KeyBinding(new RelayCommand(async() => { await rootFrame.GoBack(); }, () => rootFrame.CanGoBack), Key.Back, ModifierKeys.None));
                }
                else if (this.GetType().GetCustomAttribute <ViewAttribute>() != null || Application.Current.Resources.Contains($"View_{this.GetType().Name}"))
                {
                    this.Navigator.As <Navigator>()?.NavigateInternal <ApplicationBase>(this, null, null);
                    await this.OnPreload();

                    Application.Current.MainWindow.Activate();
                }

                await this.OnStartup(new LaunchActivatedEventArgs(e.Args));

                this.Navigator.TryClose(this);

                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.AddHookParameterPassing();
                    Application.Current.MainWindow.Activate();
                }
            }
        }
Пример #19
0
        private async void ApplicationBase_Startup(object sender, StartupEventArgs e)
        {
            this.isInitialized = true;

            if (this.UrlProtocolNames != null && this.UrlProtocolNames.Length > 0)
            {
                for (int i = 0; i < this.UrlProtocolNames.Length; i++)
                {
                    if (UrlProtocol.RequiresRegistration(this.UrlProtocolNames[i]))
                    {
                        this.OnUrlProtocolRegistration(this.UrlProtocolNames[i]);
                    }
                }

                if (e.Args.Length > 0 && e.Args[0] == "registerUriScheme")
                {
                    this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    this.Shutdown(0);
                    return;
                }
            }

            // If an application is being run by VS then it will have the .vshost suffix to its proc
            // name. We have to also check them
            var proc        = Process.GetCurrentProcess();
            var processName = proc.ProcessName.Replace(".vshost", "");
            var processes   = Process.GetProcesses().Where(x => (x.ProcessName == processName || x.ProcessName == proc.ProcessName || x.ProcessName == proc.ProcessName + ".vshost") && x.Id != proc.Id).ToArray();

            // Special case ... If we recieve a call from an uri protocol we will be passing this to
            // all instances of the application
            if (this.UrlProtocolNames != null &&
                this.UrlProtocolNames.Length > 0 &&
                e.Args.Length > 0 &&
                processes.Length > 0 &&
                this.IsUrlProtocol(e.Args))
            {
                foreach (var process in processes.Where(x => x.Id != proc.Id))
                {
                    Win32Api.SendMessage(process.MainWindowHandle, $"{e.Args.Join("\n")}");
                }

                this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                this.Shutdown();
            }

            if (this.IsSingleInstance && processes.Length > 0)
            {
                var hwnd = processes[0].MainWindowHandle;

                if (hwnd != IntPtr.Zero)
                {
                    Win32Api.SendMessage(hwnd, $"{e.Args.Join("\n")}");
                    this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    this.Shutdown();
                }
            }
            else
            {
                if (this.IsSinglePage)
                {
                    WindowType windowType = null;
                    var        window     = Common.CreateWindow(ref windowType);

                    window.ContentTemplateSelector = new CauldronTemplateSelector();

                    window.MinHeight             = 353;
                    window.MinWidth              = 502;
                    window.ShowInTaskbar         = true;
                    window.Topmost               = false;
                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                    window.WindowState           = WindowState.Normal;
                    window.Icon = await Win32Api.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location).ToBitmapImageAsync();

                    window.Title = ApplicationInfo.ApplicationName;

                    PersistentWindowInformation.Load(window, this.GetType());

                    window.SizeChanged += (s, e1) =>
                    {
                        if (window.WindowState == WindowState.Normal)
                        {
                            PersistentWindowProperties.SetHeight(window, e1.NewSize.Height);
                            PersistentWindowProperties.SetWidth(window, e1.NewSize.Width);
                        }
                    };
                    window.Closing += (s, e1) => PersistentWindowInformation.Save(window, this.GetType());

                    window.Show();

                    window.Content = this;
                    window.Activate();
                    await this.OnPreload();

                    var rootFrame = new NavigationFrame();
                    rootFrame.DataContext = this;
                    window.Content        = rootFrame;
                    window.InputBindings.Add(new KeyBinding(new RelayCommand(async() => { await rootFrame.GoBack(); }, () => rootFrame.CanGoBack), Key.Back, ModifierKeys.None));
                }
                else if (this.GetType().GetCustomAttribute <ViewAttribute>() != null || Application.Current.Resources.Contains($"View_{this.GetType().Name}"))
                {
                    this.Navigator.As <Navigator>()?.NavigateInternal <ApplicationBase>(this, null, null);
                    await this.OnPreload();

                    Application.Current.MainWindow.Activate();
                }

                await this.OnStartup(new LaunchActivatedEventArgs(e.Args));

                this.Navigator.TryClose(this);

                if (Application.Current.MainWindow != null)
                {
                    HwndSource.FromHwnd(Application.Current.MainWindow.GetWindowHandle())?.AddHook(new HwndSourceHook(HandleMessages));
                    Application.Current.MainWindow.Activate();
                }
            }
        }