private static void HookCallback(ContextRequestEventArgs args, IShowBalloonTip notifier) { EventHandler handler = null; handler = (sender, eventArgs) => { args.Callback?.Invoke(); notifier.BalloonTipClosed -= handler; }; notifier.BalloonTipClosed += handler; }
private Window InitializeWindow(ContextRequestEventArgs args) { var window = (Window)Activator.CreateInstance(WindowType); window.DataContext = args.Context; window.Title = args.Context.Title; var callback = args.Callback; EventHandler handler = null; handler = delegate { _windows.Remove(window); window.Closed -= handler; var confirmationContext = args.Context as IConfirmContext; if (confirmationContext != null) { confirmationContext.Confirmed = window.DialogResult == true; } callback?.Invoke(); }; window.Closed += handler; _windows.Add(window); if (!CenterOverAssociatedObject || AssociatedObject == null) { return(window); } SizeChangedEventHandler sizeHandler = null; sizeHandler = delegate { window.SizeChanged -= sizeHandler; var view = AssociatedObject; var position = view.PointToScreen(new Point(0, 0)); window.Top = position.Y + (view.ActualHeight - window.ActualHeight) / 2; window.Left = position.X + (view.ActualWidth - window.ActualWidth) / 2; }; window.SizeChanged += sizeHandler; return(window); }
private static void OpenDefaultWindow(ContextRequestEventArgs args) { var saveFileDialogInfo = args.Context as ISaveFileDialogInfo; if (saveFileDialogInfo != null) { var saveFileDialog = new SaveFileDialog { CreatePrompt = saveFileDialogInfo.CreatePrompt, OverwritePrompt = saveFileDialogInfo.OverwritePrompt }; HandleFileDialog(saveFileDialogInfo, saveFileDialog); args.Callback?.Invoke(); return; } var openFileDialogInfo = args.Context as IOpenFileDialogInfo; if (openFileDialogInfo != null) { var openFileDialog = new OpenFileDialog { Multiselect = openFileDialogInfo.MultiSelect, ReadOnlyChecked = openFileDialogInfo.ReadOnlyChecked, ShowReadOnly = openFileDialogInfo.ShowReadOnly }; HandleFileDialog(openFileDialogInfo, openFileDialog); args.Callback?.Invoke(); return; } var browseFolderDialogInfo = args.Context as IBrowseFolderDialogInfo; if (browseFolderDialogInfo != null) { var browseFolderDialog = new FolderBrowserDialog(); OpenFolderDialog(browseFolderDialogInfo, browseFolderDialog); args.Callback?.Invoke(); } }
protected virtual void OnRaised(ContextRequestEventArgs e) => Raised?.Invoke(this, e);