• Home
  • Documentation
Show / Hide Table of Contents
  • Introduction
  • Commands
    • Commanding
    • Composite Commands
    • Async Commands
    • Error Handling
  • Dependency Injection
    • Getting Started
    • Registering Types
    • Microsoft Extensions (Supplement)
    • Platform Specific Services
    • Exception Handling
    • ContainerLocator
    • Appendix
  • Dialog Service
    • Dialog Service
    • IDialogAware ViewModels
    • IDialogWindow (WPF & Uno Platform)
  • Event Aggregator
  • Mvvm
    • BindableBase
    • ViewModelLocator
  • Modularity
    • Getting Started
    • Module Catalog
    • Module Initialization
  • Navigation
    • Getting Started
    • INavigationParameters
    • Page Navigation
    • Regions
      • Getting Started
      • Region Manager
      • Region Adapters
      • Region Behaviors
      • About Navigation in Prism
      • Basic Region Navigation
      • View/ViewModel Participation
      • Navigating to Existing Views
      • Passing Parameters
      • Confirming Navigation
      • Controlling View Lifetime
      • Navigation Journal
  • Platforms
    • Maui
      • Getting Started
      • Migrating from Prism.Forms
      • PrismAppBuilder
      • AppModel
        • IPageLifecycleAware
      • Behaviors
        • Introduction
        • BehaviorBase<T>
        • EventToCommandBehavior
        • PageBehaviorFactory
      • Dialogs
        • Getting Started
        • IPageDialogService
      • Navigation
        • Introduction
        • Page Navigation
        • NavigationBuilder
        • TabbedPages
        • Understanding the INavigationResult
        • NavigationExceptions
        • Global Navigation Observer
        • XAML Navigation
    • Uno Platform
      • Getting Started
      • Uno.Extensions
    • Wpf
      • Introduction
      • Getting Started
      • View Composition
      • Interactivity
        • Event To Command
    • Xamarin.Forms
      • Create Your First App
      • Behaviors
        • Working with Behaviors
        • EventToCommand Behavior
        • PageBehaviorFactory
      • Dialogs
        • Dialogs
        • Page Dialog Service
        • Dialog Service
        • Styling Dialogs
      • Navigation
        • Navigation Basics
        • Passing Parameters
        • Confirming Navigation
        • Deep Linking
        • Working w/ MasterDetailPages
        • Working w/ NavigationPages
        • Working w/ TabbedPages
        • XAML Navigation
      • Application Lifecycle
      • Page Lifecycle
      • Additional Platforms
        • GTK
  • Magician
    • Getting Started
  • Plugins
    • Essentials
      • Getting Started
      • ApplicationModel
        • App Context
        • Browser
        • Communication
          • Email
          • Phone Dialer
        • Data Transfer
          • Clipboard
          • Share
        • LatestVersion
        • Launcher
        • Version Tracking
      • Devices
        • Battery
        • Sensors
          • Biometrics
          • Geocoding
          • Geofencing
          • Geolocation
      • IO
        • File System
        • Stores
      • Media
        • Getting Started
        • Camera
        • Video
      • Networking
        • Connectivity
      • Notifications
        • Getting Started
        • ActionSheets
        • Alerts
        • Prompts
      • Permissions
        • Permissions Manager
      • Threading
        • Main Thread
    • Logging
      • Getting Started
      • Interop
        • Essentials
        • Microsoft Extensions
      • Providers
        • AppCenter
        • Console
        • Debug
        • Firebase
        • Graylog
        • Kochava
        • Raygun
        • Sentry
        • Unit Testing
        • Xunit
    • Observable Regions
    • Popups
  • Pipelines
    • Commercial Plus

IDialogAware

The IDialogAware interface has undergone some updates in Prism 9 to help you write code that better meets your needs by providing a more robust API that is able to adapt to your needs.

public interface IDialogAware
{
    bool CanCloseDialog();
    void OnDialogClosed();
    void OnDialogOpened(IDialogParameters parameters)
    DialogCloseListener RequestClose { get; }
}

Can Close

The IDialogAware interface provides the method CanCloseDialog(). This allows you to provide any custom logic that you may require to determine whether or not the Dialog should be allowed to close:

public class MyDialogViewModel : IDialogAware
{
    private string? _name;
    public string? Name
    {
        get => _name;
        set => SetProperty(ref _name, value)
    }

    public bool CanCloseDialog() => !string.IsNullOrEmpty(Name);
}

DialogCloseListener

The DialogCloseListener is new in Prism 9 and replaces the event that was in the original API. The DialogCloseListener allows you more flexibility and is part of the Dialog Service's enhanced API.

Note

The RequestClose property should be implemented as shown below. This property is set by DialogService itself and should not be set by your code.

public class MyDialogViewModel : IDialogAware
{
    public DialogCloseListener RequestClose { get; }
}

Using the DialogCloseListener

One of the benefits of the DialogCloseListener is that it allows you more flexibility when invoking it.

private void OnMyCommandExecuted()
{
    // Option 1.
    RequestClose.Invoke();

    // Option 2.
    RequestClose.Invoke(new DialogParameters{ { "MyParameter", SomeValue } });

    // Option 3.
    RequestClose.Invoke(ButtonResult.OK);

    // Option 4.
    RequestClose.Invoke(new DialogParameters{ { "MyParameter", SomeValue } }, ButtonResult.OK);

    // Option 5.
    var result = new DialogResult
    {
        Parameters = new DialogParameters{ { "MyParameter", SomeValue } },
        Result = ButtonResult.OK
    };
    RequestClose.Invoke(result);
}

Additional Considerations

When building apps with .NET MAUI you may want to consider using Popup Pages. With the Commercial Plus license you can take advantage of the Prism.Plugin.Popups package for .NET MAUI.

  • Edit on GitHub
  • Ask questions
  • Follow @PrismLib
  • Follow @BrianLagunas
  • Follow @DanJSiegel
Back to top Copyright 2015-2024 Prism Software, LLC