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; }
public async static Task <UserResult> ShowDeferredContentDialog( StyleableWindow window, string title, string primaryText, string secondaryText, string primaryButton, string secondaryButton, string closeButton, int iconSymbol, ManualResetEvent deferResetEvent, Func <Window, Task> doWhileDeferred = null) { bool startedDeferring = false; UserResult result = UserResult.None; ContentDialog contentDialog = new ContentDialog { Title = title, PrimaryButtonText = primaryButton, SecondaryButtonText = secondaryButton, CloseButtonText = closeButton, Content = CreateDialogTextContent(primaryText, secondaryText, iconSymbol), PrimaryButtonCommand = MiniCommand.Create(() => { result = primaryButton == LocaleManager.Instance["InputDialogYes"] ? UserResult.Yes : UserResult.Ok; }), }; contentDialog.SecondaryButtonCommand = MiniCommand.Create(() => { contentDialog.PrimaryButtonClick -= DeferClose; result = UserResult.No; }); contentDialog.CloseButtonCommand = MiniCommand.Create(() => { contentDialog.PrimaryButtonClick -= DeferClose; result = UserResult.Cancel; }); contentDialog.PrimaryButtonClick += DeferClose; await contentDialog.ShowAsync(ContentDialogPlacement.Popup); return(result); async void DeferClose(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (startedDeferring) { return; } contentDialog.PrimaryButtonClick -= DeferClose; startedDeferring = true; var deferral = args.GetDeferral(); result = primaryButton == LocaleManager.Instance["InputDialogYes"] ? UserResult.Yes : UserResult.Ok; contentDialog.PrimaryButtonClick -= DeferClose; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(() => { deferResetEvent.WaitOne(); Dispatcher.UIThread.Post(() => { deferral.Complete(); }); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed if (doWhileDeferred != null) { await doWhileDeferred(window); deferResetEvent.Set(); } } }
public NestedCommandViewModel() { Command = MiniCommand.Create(() => { }); }
public MenuPageViewModel() { OpenCommand = MiniCommand.CreateFromTask(Open); SaveCommand = MiniCommand.Create(Save); OpenRecentCommand = MiniCommand.Create <string>(OpenRecent); var recentItems = new[] { new MenuItemViewModel { Header = "File1.txt", Command = OpenRecentCommand, CommandParameter = @"c:\foo\File1.txt" }, new MenuItemViewModel { Header = "File2.txt", Command = OpenRecentCommand, CommandParameter = @"c:\foo\File2.txt" }, }; RecentItems = recentItems; MenuItems = new[] { new MenuItemViewModel { Header = "_File", Items = new[] { new MenuItemViewModel { Header = "O_pen...", Command = OpenCommand }, new MenuItemViewModel { Header = "Save", Command = SaveCommand }, new MenuItemViewModel { Header = "-" }, new MenuItemViewModel { Header = "Recent", Items = recentItems }, } }, new MenuItemViewModel { Header = "_Edit", Items = new[] { new MenuItemViewModel { Header = "_Copy" }, new MenuItemViewModel { Header = "_Paste" }, } } }; }
public MainWindowViewModel() { ToggleDrawDirtyRects = MiniCommand.Create(() => DrawDirtyRects = !DrawDirtyRects); ToggleDrawFps = MiniCommand.Create(() => DrawFps = !DrawFps); ResizeWindow = MiniCommand.CreateFromTask(ResizeWindowAsync); }