public MainPage() { this.InitializeComponent(); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.ToastToken, msg => { ToastControl.ShowMessage(msg.Content); }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.CloseHam, msg => { if (_isDrawerSlided) { SlideOutStory.Begin(); HamburgerBtn.PlayHamOutStory(); _isDrawerSlided = false; } }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.RemoveScheduleUI, msg => { RemoveStory.Begin(); }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.ShowModifyUI, msg => { AddingPane.Visibility = Visibility.Visible; AddStory.Begin(); }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.ChangeCommandBarToDelete, msg => { SwitchCommandBarToDelete.Begin(); }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.ChangeCommandBarToDefault, msg => { SwitchCommandBarToDefault.Begin(); }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.GoToSort, act => { DisplayedListView.CanDragItems = true; DisplayedListView.CanReorderItems = true; DisplayedListView.AllowDrop = true; }); Messenger.Default.Register <GenericMessage <string> >(this, MessengerTokens.LeaveSort, act => { DisplayedListView.CanDragItems = false; DisplayedListView.CanReorderItems = false; DisplayedListView.AllowDrop = true; }); RemoveStory.Completed += ((senderc, ec) => { _isAddingPaneShowed = false; }); this.KeyDown += ((sender, e) => { if (_isAddingPaneShowed && e.Key == Windows.System.VirtualKey.Enter && e.KeyStatus.RepeatCount == 1) { Messenger.Default.Send(new GenericMessage <string>(""), MessengerTokens.EnterToAdd); RemoveStory.Begin(); } }); }
/// <summary> /// Copy text in OCR result into clipboard /// </summary> private void CopyTextCommandExecute() { bool copiedText = TranslationVisibility == Visibility.Visible ? ClipboardManager.Copy(TranslatedText) : ClipboardManager.Copy(Text); ToastControl toast = new ToastControl(copiedText ? Resources.Message_CopiedToClipboard : Resources.Message_CopyToClipboardFailed); toast.ShowInMainWindow(); }
public ToastNotification(Icon toastIcon) { _syncContext = System.Threading.SynchronizationContext.Current; if (toastIcon == null) { _toastImage = null; } else { _toastImage = toastIcon.ToBitmap(maxWidth: 32, minWidth: 32); } _toastControl = new ToastControl(_toastImage) { Dock = DockStyle.Fill }; _toastForm = new Form() { Name = "ToastNotification", AutoSize = false, StartPosition = FormStartPosition.Manual, FormBorderStyle = FormBorderStyle.None, ShowInTaskbar = false, Padding = new Padding(0), TopMost = true, Size = new Size(160, 48) }; _toastForm.Controls.Add(_toastControl); _toastTimer = new Timer(); _toastTimer.Tick += ToastTimer_Tick; }
public ToastNotificationServiceTest() { _wpfTextView = CreateTextView(); _editorFormatMap = CompositionContainer.GetExportedValue <IEditorFormatMapService>().GetEditorFormatMap(_wpfTextView); _toastNotificationServiceRaw = new ToastNotificationService(_wpfTextView, _editorFormatMap); _toastNotificationService = _toastNotificationServiceRaw; _toastControl = _toastNotificationServiceRaw.ToastControl; }
/// <summary> /// 通过UI线程,在当前窗体显示 “弹出消息”,默认 10 秒后自动消失 /// <para>如果 自动消失时间 小于等于 0,则不会自动消失,只能通过鼠标点击隐藏</para> /// </summary> /// <param name="pMessage">要显示的内容</param> /// <param name="pHideMessageSeconds">自动消失时间,默认 10 秒</param> public static void Show(object pMessage, double pHideMessageSeconds = 10) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { Application.Current.Windows .Cast <Window>() .Where(dd => dd.IsActive) .ForFirst(iWin => { Grid panel; //其他类型的容器(不支持多级Child) if ((iWin.Content as Grid)?.Name != "ShellGridForSingleCell") { //改为嵌套一个支持多级Child的容器 var oldContent = iWin.Content as UIElement; iWin.Content = null; var grid = new Grid() { Name = "ShellGridForSingleCell" }; grid.Children.Add(oldContent); iWin.Content = grid; panel = grid; } else { panel = (Grid)iWin.Content; } // 手动 隐藏旧的提示 panel.Children.OfType <ToastControl>() .ToList() .ForEach(dd => panel.Children.Remove(dd)); // 重新显示提示信息 var toast = new ToastControl { FlyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(pHideMessageSeconds)), Content = pMessage }; panel.Children.Add(toast); }); }), null); }
public LoginPage() { this.InitializeComponent(); this.KeyDown += LoginPage_KeyDown; LoginVM = new LoginViewModel(); this.DataContext = LoginVM; if (ApiInformationHelper.HasStatusBar()) { StatusBar.GetForCurrentView().BackgroundColor = (App.Current.Resources["MyerListBlueLight"] as SolidColorBrush).Color; StatusBar.GetForCurrentView().BackgroundOpacity = 0.01; StatusBar.GetForCurrentView().ForegroundColor = Colors.White; } Messenger.Default.Register <GenericMessage <string> >(this, "toast", act => { var msg = act.Content; ToastControl.ShowMessage(msg); }); }
private void OnBeforeTransitionBetweenPages() { ToastControl.HideAllToasts(); }