-
Notifications
You must be signed in to change notification settings - Fork 39
Upgrading to Prism v9.0
Damian edited this page Apr 13, 2024
·
9 revisions
WARNING: Work in progress
- Namespace:
Prism.Regions
->Prism.Navigation.Regions
-
IDialogService
andIDialogAware
- New closing mechanism.
- Closing a dialog via
RequestClose
changed fromevent
toDialogCloseListener
- Showing a dialog no longer requires the parent window as a parameter.
- Setting a custom ParentWindow with,
KnownDialogParameters.ParentWindow
- By default the parent window is the root main window.
- You can set an alternate
Window
via the DialogParameter,KnownDialogParameters.ParentWindow
- Sample (from *.axaml.cs):
new DialogParameters() { { KnownDialogParameters.ParentWindow, this.Parent} });
- Setting a custom dialog window with
KnownDialogParameters.WindowName
// NEW:
_dialogService.ShowDialog(
nameof(MessageBoxView),
new DialogParameters($"title={title}&message={message}"));
// OLD:
_dialogService.ShowDialog(
nameof(MessageBoxView),
new DialogParameters($"title={title}&message={message}"));
public class MessageBoxViewModel : BindableBase, IDialogAware
{
// v9.0.271-pre
public DialogCloseListener RequestClose { get; }
// v8.1.97
// public event Action<IDialogResult>? RequestClose;
public DelegateCommand<string> CmdResult => new DelegateCommand<string>((param) =>
{
// None = 0, OK = 1, Cancel = 2, Abort = 3, Retry = 4, Ignore = 5, Yes = 6, No = 7
ButtonResult result = ButtonResult.None;
if (int.TryParse(param, out int intResult))
result = (ButtonResult)intResult;
// v9.0.271-pre
RequestClose.Invoke(result);
// v8.1.97
// RaiseRequestClose(new DialogResult(result));
});
/// <summary>Allow the dialog to close</summary>
public virtual bool CanCloseDialog() => true;
public virtual void OnDialogClosed()
{
// Detach custom event handlers here, etc.
}
public void OnDialogOpened(IDialogParameters parameters)
{
var title = parameters.GetValue<string>("title");
if (!string.IsNullOrEmpty(title))
Title = title;
CustomMessage = parameters.GetValue<string>("message");
}
// v8.1.97
//public virtual void RaiseRequestClose(IDialogResult dialogResult)
//{
// RequestClose?.Invoke(dialogResult);
//}
}