public static async Task<object> Show(object content, object dialogIndetifier, DialogClosingEventHandler closingEventHandler) { if (content == null) throw new ArgumentNullException(nameof(content)); if (LoadedInstances.Count == 0) throw new InvalidOperationException("No loaded DialogHost instances."); LoadedInstances.First().Dispatcher.VerifyAccess(); var targets = LoadedInstances.Where(dh => Equals(dh.Identifier, dialogIndetifier)).ToList(); if (targets.Count == 0) throw new InvalidOperationException("No loaded DialogHost matches identifier."); if (targets.Count > 1) throw new InvalidOperationException("Multiple viable DialogHosts. Specify a unique identifier."); if (targets[0].IsOpen) throw new InvalidOperationException("DialogHost is already open."); targets[0].AssertTargetableContent(); targets[0].DialogContent = content; targets[0].SetCurrentValue(IsOpenProperty, true); targets[0]._asyncShowClosingEventHandler = closingEventHandler; var task = new Task(() => { targets[0]._asyncShowWaitHandle.WaitOne(); }); task.Start(); await task; targets[0]._asyncShowClosingEventHandler = null; return targets[0]._closeDialogExecutionParameter; }
public async Task ShowAsync(object o, string dialogID, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { await DialogHost.Show(o, dialogID, openedEventHandler, closingEventHandler); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="dialogIdentifier"><see cref="Identifier"/> of the instance where the dialog should be shown. Typically this will match an identifer set in XAML. <c>null</c> is allowed.</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task <object> Show(object content, object dialogIdentifier, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (LoadedInstances.Count == 0) { throw new InvalidOperationException("No loaded DialogHost instances."); } LoadedInstances.First().Dispatcher.VerifyAccess(); var targets = LoadedInstances.Where(dh => Equals(dh.Identifier, dialogIdentifier)).ToList(); if (targets.Count == 0) { throw new InvalidOperationException("No loaded DialogHost have an Identifier property matching dialogIndetifier argument."); } if (targets.Count > 1) { throw new InvalidOperationException("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern."); } if (targets[0].IsOpen) { throw new InvalidOperationException("DialogHost is already open."); } targets[0].AssertTargetableContent(); targets[0].DialogContent = content; targets[0]._asyncShowOpenedEventHandler = openedEventHandler; targets[0]._asyncShowClosingEventHandler = closingEventHandler; targets[0].SetCurrentValue(IsOpenProperty, true); var task = new Task(() => { targets[0]._asyncShowWaitHandle.WaitOne(); }); task.Start(); await task; targets[0]._asyncShowOpenedEventHandler = null; targets[0]._asyncShowClosingEventHandler = null; return(targets[0]._closeDialogExecutionParameter); }
/// <summary> /// Shows a dialog using the first found <see cref="DialogHost"/> in a given <see cref="Window"/>. /// </summary> /// <param name="window">Window on which the modal dialog should be displayed. Must contain a <see cref="DialogHost"/>.</param> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <exception cref="InvalidOperationException"> /// Thrown is a <see cref="DialogHost"/> is not found when conducting a depth first traversal of visual tree. /// </exception> /// <remarks> /// As a depth first traversal of the window's visual tree is performed, it is not safe to use this method in a situtation where a screen has multiple <see cref="DialogHost"/>s. /// </remarks> /// <returns></returns> public static Task <object> ShowDialog(this Window window, object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return(GetFirstDialogHost(window).ShowInternal(content, openedEventHandler, closingEventHandler)); }
internal async Task<object> ShowInternal(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (IsOpen) throw new InvalidOperationException("DialogHost is already open."); AssertTargetableContent(); DialogContent = content; _asyncShowOpenedEventHandler = openedEventHandler; _asyncShowClosingEventHandler = closingEventHandler; SetCurrentValue(IsOpenProperty, true); var task = new Task(() => { _asyncShowWaitHandle.WaitOne(); }); task.Start(); await task; _asyncShowOpenedEventHandler = null; _asyncShowClosingEventHandler = null; return _closeDialogExecutionParameter; }
public static async Task <OpenDirectoryDialogResult> ShowDialogAsync(string dialogHostName, double?width = null, double?height = null, string currentDirectory = null, bool showHiddenFilesAndDirectories = false, bool showSystemFilesAndDirectories = false, DialogOpenedEventHandler openedHandler = null, DialogClosingEventHandler closingHandler = null) { OpenDirectoryDialog dialog = InitDialog(width, height, currentDirectory, showHiddenFilesAndDirectories, showSystemFilesAndDirectories); return(await DialogHost.Show(dialog, dialogHostName, openedHandler, closingHandler) as OpenDirectoryDialogResult); }
private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) { if (executedRoutedEventArgs.Handled) return; var dependencyObject = executedRoutedEventArgs.OriginalSource as DependencyObject; if (dependencyObject != null) { _attachedDialogOpenedEventHandler = GetDialogOpenedAttached(dependencyObject); _attachedDialogClosingEventHandler = GetDialogClosingAttached(dependencyObject); } if (executedRoutedEventArgs.Parameter != null) { AssertTargetableContent(); //TODO enhancement: make the following configurable, so that the data context can be pulled from the dialog host if desired. // (leave the current behaviour as the default; most developers will find this logical, as the data context will "inherit" from button containing the content) var contentElement = executedRoutedEventArgs.Parameter as FrameworkElement; var senderElement = executedRoutedEventArgs.OriginalSource as FrameworkElement; if (contentElement != null && senderElement != null && contentElement.DataContext == null && BindingOperations.GetBindingExpression(contentElement, DataContextProperty) == null) { DialogContent = executedRoutedEventArgs.Parameter; contentElement.SetCurrentValue(DataContextProperty, senderElement.DataContext); } else DialogContent = executedRoutedEventArgs.Parameter; } SetCurrentValue(IsOpenProperty, true); executedRoutedEventArgs.Handled = true; }
/// <summary> /// Shows a dialog using the parent/ancestor <see cref="DialogHost"/> of the a given <see cref="DependencyObject"/>. /// </summary> /// <param name="childDependencyObject">Dependency object which should be a visual child of a <see cref="DialogHost"/>, where the dialog will be shown.</param> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <exception cref="InvalidOperationException"> /// Thrown is a <see cref="DialogHost"/> is not found when conducting a depth first traversal of visual tree. /// </exception> /// <returns></returns> public static async Task<object> ShowDialog(this DependencyObject childDependencyObject, object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return await GetOwningDialogHost(childDependencyObject).ShowInternal(content, openedEventHandler, closingEventHandler); }
public void TextTips(InfoListModel message, Action <InfoListModel> action, DialogClosingEventHandler e = null) { MainWindow.indexoffline.TextTips(message, action, e); }
/// <summary> /// Shows a dialog using the first found <see cref="DialogHost"/> in a given <see cref="Window"/>. /// </summary> /// <param name="window">Window on which the modal dialog should be displayed. Must contain a <see cref="DialogHost"/>.</param> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <exception cref="InvalidOperationException"> /// Thrown is a <see cref="DialogHost"/> is not found when conducting a depth first traversal of visual tree. /// </exception> /// <remarks> /// As a depth first traversal of the window's visual tree is performed, it is not safe to use this method in a situtation where a screen has multiple <see cref="DialogHost"/>s. /// </remarks> /// <returns></returns> public static async Task <object> ShowDialog(this Window window, object content, DialogClosingEventHandler closingEventHandler) { return(await GetFirstDialogHost(window).ShowInternal(content, null, closingEventHandler)); }
/// <summary> /// Shows a dialog using the parent/ancestor <see cref="DialogHost"/> of the a given <see cref="DependencyObject"/>. /// </summary> /// <param name="childDependencyObject">Dependency object which should be a visual child of a <see cref="DialogHost"/>, where the dialog will be shown.</param> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <exception cref="InvalidOperationException"> /// Thrown is a <see cref="DialogHost"/> is not found when conducting a depth first traversal of visual tree. /// </exception> /// <returns></returns> public static async Task <object> ShowDialog(this DependencyObject childDependencyObject, object content, DialogClosingEventHandler closingEventHandler) { return(await GetOwningDialogHost(childDependencyObject).ShowInternal(content, null, closingEventHandler)); }
public override Task <bool> ShowDialog(DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { var dialog = GetDialogWindow(); dialog.ShowDialog(); var r = (dialog.DataContext as BaseDialogOperation).Result; return(Task.FromResult(r)); }
internal Task <object> ShowInternal(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (IsOpen) { IsOpen = false; //throw new InvalidOperationException("DialogHost is already open."); } AssertTargetableContent(); DialogContent = content; _asyncShowOpenedEventHandler = openedEventHandler; _asyncShowClosingEventHandler = closingEventHandler; SetCurrentValue(IsOpenProperty, true); //SetPopupScreen((UserControl)DialogContent); var task = new Task(() => { _asyncShowWaitHandle.WaitOne(); }).ContinueWith(t => { _asyncShowOpenedEventHandler = null; _asyncShowClosingEventHandler = null; return(_closeDialogExecutionParameter); }); return(task); }
public static Task <object> Show(object content, DialogOpenedEventHandler openedEventHandler = null, DialogClosingEventHandler closingEventHandler = null) { return(Application.Current.Dispatcher.Invoke(() => { CloseDialog(); return DialogHost.Show(content, openedEventHandler, closingEventHandler); })); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="dialogIdentifier"><see cref="Identifier"/> of the instance where the dialog should be shown. Typically this will match an identifer set in XAML. <c>null</c> is allowed.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static Task <object> Show(object content, object dialogIdentifier, DialogClosingEventHandler closingEventHandler) { return(Show(content, dialogIdentifier, null, closingEventHandler)); }
internal async Task <object> ShowInternal(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (IsOpen) { throw new InvalidOperationException("DialogHost is already open."); } AssertTargetableContent(); DialogContent = content; _asyncShowOpenedEventHandler = openedEventHandler; _asyncShowClosingEventHandler = closingEventHandler; SetCurrentValue(IsOpenProperty, true); var task = new Task(() => { _asyncShowWaitHandle.WaitOne(); }); task.Start(); await task; _asyncShowOpenedEventHandler = null; _asyncShowClosingEventHandler = null; return(_closeDialogExecutionParameter); }
public void AddTips(Action <InfoListModel> action, DialogClosingEventHandler e = null) { MainWindow.indexoffline.AddTips(action, e); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="dialogIndetifier"><see cref="Identifier"/> of the instance where the dialog should be shown. Typically this will match an identifer set in XAML. <c>null</c> is allowed.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static Task<object> Show(object content, object dialogIndetifier, DialogClosingEventHandler closingEventHandler) { return Show(content, dialogIndetifier, null, closingEventHandler); }
private Task <object> ShowDialog(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler dialogClosingEventHandler) { HashSet <DialogHost> instances = (HashSet <DialogHost>)dialogInstancesField.GetValue(null); if (instances != null) { if (instances.Count == 0) { throw new InvalidOperationException("No loaded DialogHost instances."); } DialogHost host = instances.First(); if (host.IsOpen) { host.IsOpen = false; } return(host.ShowDialog(content, openedEventHandler, dialogClosingEventHandler)); } return(DialogHost.Show(content, openedEventHandler, dialogClosingEventHandler)); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task <object?> Show(object content, DialogClosingEventHandler closingEventHandler) => await Show(content, null, null, closingEventHandler);
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="dialogIdentifier"><see cref="Identifier"/> of the instance where the dialog should be shown. Typically this will match an identifer set in XAML. <c>null</c> is allowed.</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task <object> Show(object content, object dialogIdentifier, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (content is null) { throw new ArgumentNullException(nameof(content)); } return(await GetInstance(dialogIdentifier).ShowInternal(content, openedEventHandler, closingEventHandler)); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="dialogIdentifier"><see cref="Identifier"/> of the instance where the dialog should be shown. Typically this will match an identifer set in XAML. <c>null</c> is allowed.</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task<object> Show(object content, object dialogIdentifier, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (content == null) throw new ArgumentNullException(nameof(content)); if (LoadedInstances.Count == 0) throw new InvalidOperationException("No loaded DialogHost instances."); LoadedInstances.First().Dispatcher.VerifyAccess(); var targets = LoadedInstances.Where(dh => Equals(dh.Identifier, dialogIdentifier)).ToList(); if (targets.Count == 0) throw new InvalidOperationException("No loaded DialogHost have an Identifier property matching dialogIndetifier argument."); if (targets.Count > 1) throw new InvalidOperationException("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern."); return await targets[0].ShowInternal(content, openedEventHandler, closingEventHandler); }
public static async Task <SaveFileDialogResult> ShowDialogAsync(DialogHost dialogHost, double?width = null, double?height = null, string currentDirectory = null, string filename = null, bool showHiddenFilesAndDirectories = false, bool showSystemFilesAndDirectories = false, DialogOpenedEventHandler openedHandler = null, DialogClosingEventHandler closingHandler = null) { SaveFileDialog dialog = InitDialog(width, height, currentDirectory, filename, null, -1, showHiddenFilesAndDirectories, showSystemFilesAndDirectories); return(await dialogHost.ShowDialog(dialog, openedHandler, closingHandler) as SaveFileDialogResult); }
/// <summary> /// Shows a dialog using the parent/ancestor <see cref="DialogHost"/> of the a given <see cref="DependencyObject"/>. /// </summary> /// <param name="childDependencyObject">Dependency object which should be a visual child of a <see cref="DialogHost"/>, where the dialog will be shown.</param> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <exception cref="InvalidOperationException"> /// Thrown is a <see cref="DialogHost"/> is not found when conducting a depth first traversal of visual tree. /// </exception> /// <returns></returns> public static Task <object> ShowDialog(this DependencyObject childDependencyObject, object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return(GetOwningDialogHost(childDependencyObject).ShowInternal(content, openedEventHandler, closingEventHandler)); }
public override Task <bool> ShowDialog(DialogOpenedEventHandler openedEventHandler = null, DialogClosingEventHandler closingEventHandler = null) { GetDialogWindow().ShowDialog(); return(Task.FromResult(true)); }
public Task ShowAsync(object o, string dialogID, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { PassedObject = o; DialogID = dialogID; NumberOfCalls++; var viewModel = o as ProgressControlViewModel; viewModel.OnCompleted += ViewModel_OnCompleted; openedEventHandler.Invoke(this, null); waitHandle.WaitOne(); return(Task.CompletedTask); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static object Show(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return(Show(content, null, openedEventHandler, closingEventHandler)); }
public static void SetDialogClosingAttached(DependencyObject element, DialogClosingEventHandler value) { element.SetValue(DialogClosingAttachedProperty, value); }
internal async Task <object> ShowInternal(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (IsOpen) { throw new InvalidOperationException("DialogHost is already open."); } _dialogTaskCompletionSource = new TaskCompletionSource <object>(); AssertTargetableContent(); DialogContent = content; _asyncShowOpenedEventHandler = openedEventHandler; _asyncShowClosingEventHandler = closingEventHandler; SetCurrentValue(IsOpenProperty, true); object result = await _dialogTaskCompletionSource.Task; _asyncShowOpenedEventHandler = null; _asyncShowClosingEventHandler = null; return(result); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task <object> Show(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return(await Show(content, null, openedEventHandler, closingEventHandler)); }
public async void TextTips(InfoListModel infoListModel, Action <InfoListModel> action, DialogClosingEventHandler e = null) { try { if (e == null) { e = closingEventHandler; } var textDialog = new TextDialog() { Text_CardAddress = { Text = infoListModel.address }, Text_Name = { Text = infoListModel.userName }, Text_Card = { Text = infoListModel.cardNo }, Text_Sex = { Text = infoListModel.sex }, Text_homeAddress = { Text = infoListModel.address }, Text_company = { Text = infoListModel.company } }; await DialogHost.Show(textDialog, "ReadDialog"); action(textDialog.InfoListModel); } catch (Exception ex) { Logger.Default.Error(ex.Message); } }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="dialogIdentifier"><see cref="Identifier"/> of the instance where the dialog should be shown. Typically this will match an identifer set in XAML. <c>null</c> is allowed.</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task <object> Show(object content, object dialogIdentifier, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (LoadedInstances.Count == 0) { throw new InvalidOperationException("No loaded DialogHost instances."); } LoadedInstances.First().Dispatcher.VerifyAccess(); var targets = LoadedInstances.Where(dh => Equals(dh.Identifier, dialogIdentifier)).ToList(); if (targets.Count == 0) { throw new InvalidOperationException("No loaded DialogHost have an Identifier property matching dialogIndetifier argument."); } if (targets.Count > 1) { throw new InvalidOperationException("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern."); } return(await targets[0].ShowInternal(content, openedEventHandler, closingEventHandler)); }
/// <summary> /// 弹出窗口 /// </summary> /// <param name="openedEventHandler"></param> /// <param name="closingEventHandler"></param> /// <returns></returns> public async virtual Task <bool> ShowDialog(DialogOpenedEventHandler openedEventHandler = null, DialogClosingEventHandler closingEventHandler = null) { var dialog = GetDialog(); object taskResult = await DialogHost.Show(dialog, "RootDialog", openedEventHandler, closingEventHandler); //位于顶级窗口 return((bool)taskResult); }
private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) { if (executedRoutedEventArgs.Handled) return; var dependencyObject = executedRoutedEventArgs.OriginalSource as DependencyObject; if (dependencyObject != null) { _attachedDialogOpenedEventHandler = GetDialogOpenedAttached(dependencyObject); _attachedDialogClosingEventHandler = GetDialogClosingAttached(dependencyObject); } if (executedRoutedEventArgs.Parameter != null) { AssertTargetableContent(); if (_popupContentControl != null) { switch (OpenDialogCommandDataContextSource) { case DialogHostOpenDialogCommandDataContextSource.SenderElement: _popupContentControl.DataContext = (executedRoutedEventArgs.Parameter as FrameworkElement)?.DataContext; break; case DialogHostOpenDialogCommandDataContextSource.DialogHostInstance: _popupContentControl.DataContext = DataContext; break; case DialogHostOpenDialogCommandDataContextSource.None: _popupContentControl.DataContext = null; break; default: throw new ArgumentOutOfRangeException(); } } DialogContent = executedRoutedEventArgs.Parameter; } SetCurrentValue(IsOpenProperty, true); executedRoutedEventArgs.Handled = true; }
private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) { if (executedRoutedEventArgs.Handled) return; var dependencyObject = executedRoutedEventArgs.OriginalSource as DependencyObject; if (dependencyObject != null) { _attachedDialogClosingEventHandler = GetDialogClosingAttached(dependencyObject); } if (executedRoutedEventArgs.Parameter != null) { AssertTargetableContent(); DialogContent = executedRoutedEventArgs.Parameter; } SetCurrentValue(IsOpenProperty, true); executedRoutedEventArgs.Handled = true; }
/// <summary> /// Shows a dialog using the first found <see cref="DialogHost"/> in a given <see cref="Window"/>. /// </summary> /// <param name="window">Window on which the modal dialog should be displayed. Must contain a <see cref="DialogHost"/>.</param> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <exception cref="InvalidOperationException"> /// Thrown is a <see cref="DialogHost"/> is not found when conducting a depth first traversal of visual tree. /// </exception> /// <remarks> /// As a depth first traversal of the window's visual tree is performed, it is not safe to use this method in a situtation where a screen has multiple <see cref="DialogHost"/>s. /// </remarks> /// <returns></returns> public static async Task<object> ShowDialog(this Window window, object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return await GetFirstDialogHost(window).ShowInternal(content, openedEventHandler, closingEventHandler); }
public static Task <object> PopupDialog(this UserControl con, object dialogIdentifier = null, DialogOpenedEventHandler openedEventHandler = null, DialogClosingEventHandler closingEventHandler = null) //必须为public static 类型,且参数使用this关键字 { return(Application.Current.Dispatcher.Invoke <Task <object> >(() => { return DialogHost.Show(con, dialogIdentifier, openedEventHandler, closingEventHandler); })); }
public static void CloseDialog(this UserControl con, object dialogIdentifier = null, DialogOpenedEventHandler openedEventHandler = null, DialogClosingEventHandler closingEventHandler = null) //必须为public static 类型,且参数使用this关键字 { Application.Current.Dispatcher.Invoke(() => { DialogHost.CloseDialogCommand.Execute(con, con); //return DialogHost.close(con, dialogIdentifier, openedEventHandler, closingEventHandler); }); }
/// <summary> /// Shows a modal dialog. To use, a <see cref="DialogHost"/> instance must be in a visual tree (typically this may be specified towards the root of a Window's XAML). /// </summary> /// <param name="content">Content to show (can be a control or view model).</param> /// <param name="openedEventHandler">Allows access to opened event which would otherwise have been subscribed to on a instance.</param> /// <param name="closingEventHandler">Allows access to closing event which would otherwise have been subscribed to on a instance.</param> /// <returns>Task result is the parameter used to close the dialog, typically what is passed to the <see cref="CloseDialogCommand"/> command.</returns> public static async Task<object> Show(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { return await Show(content, null, openedEventHandler, closingEventHandler); }
public async Task ShowAsync(object o, string dialogID, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler closingEventHandler) { var control = new OperationProcessingControl(); control.DataContext = o; await DialogHost.Show(control, dialogID, openedEventHandler, closingEventHandler); }