示例#1
0
        public MainWindowViewModel(IManagedNotificationManager notificationManager)
        {
            _notificationManager = notificationManager;

            ShowCustomManagedNotificationCommand = ReactiveCommand.Create(() =>
            {
                NotificationManager.Show(new NotificationViewModel(NotificationManager)
                {
                    Title = "Hey There!", Message = "Did you know that Avalonia now supports Custom In-Window Notifications?"
                });
            });

            ShowManagedNotificationCommand = ReactiveCommand.Create(() =>
            {
                NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Welcome", "Avalonia now supports Notifications.", NotificationType.Information));
            });

            ShowNativeNotificationCommand = ReactiveCommand.Create(() =>
            {
                NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Error", "Native Notifications are not quite ready. Coming soon.", NotificationType.Error));
            });

            AboutCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var dialog = new AboutAvaloniaDialog();

                var mainWindow = (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;

                await dialog.ShowDialog(mainWindow);
            });

            ExitCommand = ReactiveCommand.Create(() =>
            {
                (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).Shutdown();
            });

            ToggleMenuItemCheckedCommand = ReactiveCommand.Create(() =>
            {
                IsMenuItemChecked = !IsMenuItemChecked;
            });

            WindowState = WindowState.Normal;

            WindowStates = new WindowState[]
            {
                WindowState.Minimized,
                WindowState.Normal,
                WindowState.Maximized,
                WindowState.FullScreen,
            };
        }
        private static NativeMenu CreateDefaultAppMenu()
        {
            var result = new NativeMenu();

            var aboutItem = new NativeMenuItem
            {
                Header = "About Avalonia",
            };

            aboutItem.Click += async(sender, e) =>
            {
                var dialog = new AboutAvaloniaDialog();

                var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;

                await dialog.ShowDialog(mainWindow);
            };

            result.Add(aboutItem);

            return(result);
        }
示例#3
0
        public MainWindowViewModel(IManagedNotificationManager notificationManager)
        {
            _notificationManager = notificationManager;

            ShowCustomManagedNotificationCommand = MiniCommand.Create(() =>
            {
                NotificationManager.Show(new NotificationViewModel(NotificationManager)
                {
                    Title = "Hey There!", Message = "Did you know that Avalonia now supports Custom In-Window Notifications?"
                });
            });

            ShowManagedNotificationCommand = MiniCommand.Create(() =>
            {
                NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Welcome", "Avalonia now supports Notifications.", NotificationType.Information));
            });

            ShowNativeNotificationCommand = MiniCommand.Create(() =>
            {
                NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Error", "Native Notifications are not quite ready. Coming soon.", NotificationType.Error));
            });

            AboutCommand = MiniCommand.CreateFromTask(async() =>
            {
                var dialog = new AboutAvaloniaDialog();

                var mainWindow = (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;

                await dialog.ShowDialog(mainWindow);
            });

            ExitCommand = MiniCommand.Create(() =>
            {
                (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).Shutdown();
            });

            ToggleMenuItemCheckedCommand = MiniCommand.Create(() =>
            {
                IsMenuItemChecked = !IsMenuItemChecked;
            });

            WindowState = WindowState.Normal;

            WindowStates = new WindowState[]
            {
                WindowState.Minimized,
                WindowState.Normal,
                WindowState.Maximized,
                WindowState.FullScreen,
            };

            this.WhenAnyValue(x => x.SystemTitleBarEnabled, x => x.PreferSystemChromeEnabled)
            .Subscribe(x =>
            {
                var hints = ExtendClientAreaChromeHints.NoChrome | ExtendClientAreaChromeHints.OSXThickTitleBar;

                if (x.Item1)
                {
                    hints |= ExtendClientAreaChromeHints.SystemChrome;
                }

                if (x.Item2)
                {
                    hints |= ExtendClientAreaChromeHints.PreferSystemChrome;
                }

                ChromeHints = hints;
            });

            SystemTitleBarEnabled = true;
            TitleBarHeight        = -1;
        }
示例#4
0
        private NativeMenu CreateDefaultAppMenu()
        {
            var result = new NativeMenu();

            var aboutItem = new NativeMenuItem("About Avalonia");

            aboutItem.Click += async(sender, e) =>
            {
                var dialog = new AboutAvaloniaDialog();

                var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;

                await dialog.ShowDialog(mainWindow);
            };
            result.Add(aboutItem);

            var macOpts = AvaloniaLocator.Current.GetService <MacOSPlatformOptions>();

            if (macOpts == null || !macOpts.DisableDefaultApplicationMenuItems)
            {
                result.Add(new NativeMenuItemSeparator());

                var servicesMenu = new NativeMenuItem("Services");
                servicesMenu.Menu = new NativeMenu
                {
                    [MacOSNativeMenuCommands.IsServicesSubmenuProperty] = true
                };
                result.Add(servicesMenu);

                result.Add(new NativeMenuItemSeparator());

                var hideItem = new NativeMenuItem("Hide " + Application.Current.Name)
                {
                    Gesture = new KeyGesture(Key.H, KeyModifiers.Meta)
                };
                hideItem.Click += (sender, args) =>
                {
                    _applicationCommands.HideApp();
                };
                result.Add(hideItem);


                var hideOthersItem = new NativeMenuItem("Hide Others")
                {
                    Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta | KeyModifiers.Alt)
                };
                hideOthersItem.Click += (sender, args) =>
                {
                    _applicationCommands.HideOthers();
                };
                result.Add(hideOthersItem);


                var showAllItem = new NativeMenuItem("Show All");
                showAllItem.Click += (sender, args) =>
                {
                    _applicationCommands.ShowAll();
                };
                result.Add(showAllItem);

                result.Add(new NativeMenuItemSeparator());

                var quitItem = new NativeMenuItem("Quit")
                {
                    Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta)
                };
                quitItem.Click += (sender, args) =>
                {
                    _applicationCommands.ShowAll();
                };
                result.Add(quitItem);
            }


            return(result);
        }