Solution:
Create a new class dialogserviceextend, and then register it in the
public class DialogServiceExtend : DialogService
{
public DialogServiceExtend(IContainerExtension containerExtension) : base(containerExtension)
{
}
protected override void ConfigureDialogWindowEvents(IDialogWindow dialogWindow, Action<IDialogResult> callback)
{
Action<IDialogResult> requestCloseHandler = null;
requestCloseHandler = (o) =>
{
dialogWindow.Result = o;
dialogWindow.Close();
};
RoutedEventHandler loadedHandler = null;
loadedHandler = (o, e) =>
{
dialogWindow.Loaded -= loadedHandler;
GetDialogViewModel(dialogWindow).RequestClose += requestCloseHandler;
};
dialogWindow.Loaded += loadedHandler;
CancelEventHandler closingHandler = null;
closingHandler = (o, e) =>
{
if (!GetDialogViewModel(dialogWindow).CanCloseDialog())
{
callback?.Invoke(dialogWindow.Result);
e.Cancel = true;
}
};
dialogWindow.Closing += closingHandler;
EventHandler closedHandler = null;
closedHandler = (o, e) =>
{
dialogWindow.Closed -= closedHandler;
dialogWindow.Closing -= closingHandler;
GetDialogViewModel(dialogWindow).RequestClose -= requestCloseHandler;
GetDialogViewModel(dialogWindow).OnDialogClosed();
if (dialogWindow.Result == null)
dialogWindow.Result = new DialogResult();
callback?.Invoke(dialogWindow.Result);
dialogWindow.DataContext = null;
dialogWindow.Content = null;
};
dialogWindow.Closed += closedHandler;
}
private IDialogAware GetDialogViewModel(IDialogWindow dialogWindow)
{
return (IDialogAware)dialogWindow.DataContext;
}
}
register
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IDialogService, DialogServiceExtend>();
}
Then you can find that the callback can take effect
Similar Posts:
- dynamic_cast Error: source type is not polymorphic
- [Solved] Mybatis Codes Error: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver
- [Solved] Java Call Error: java.lang.IllegalArgumentException: wrong number of arguments
- Compatibility issues with microsoft.toolkit.mvvm (MVVM Toolkit)
- System.Data.SqlTypes.SqlNullValueException: ‘Data is Null. This method or property cannot be called on Null values.’
- [Solved] handycontrol: numericupdown Fail to display custom error
- Two solutions to cross origin read blocking (CORB) blocked cross origin response error of Web Service API
- [Solved] EF An error occurred while updating the entries. See the inner exception for details.
- [Solved] IllegalArgumentException: object is not an instance of declaring class
- Convert Object to List>, avoiding Unchecked cast: ‘java.lang.Object’ to ‘java.util.List