Search code examples
.net-coreprismprism-7

modal dialog in prism 7.2


I'm developing an .net core 3 wpf Prism application and I want to know how is it possible, with the new IDIalogAware interface in Prism 7.2, to have the main window grayed out when the modal dialog shows. I'm searching for something like the property DialogLayout.MaskStyle in Prism xamarin.forms?


Solution

  • Put a "fog" control topmost in your mainwindow, hidden by default. Bind its visibility to a property on the shell view model. Create a service that this property redirects to. Inject the service into your modal dialog's view model, too. Use it to activate the fog from OnDialogOpened and deactivate it from OnDialogClosed.

    Edit: a bit of example code for the "redirect"-part...

    public interface IFogController : INotifyPropertyChanged
    {
        bool IsFogVisible { get; set; }
    }
    
    internal class ShellViewModel : BindableBase
    {
        public ShellViewModel( IFogController fogController )
        {
            _fogController = fogController;
            PropertyChangedEventManager.AddHandler( fogController, ( sender, args ) => RaisePropertyChanged( nameof(IsFogVisible) ), nameof( IFogController.IsFogVisible ) );
        }
    
        public bool IsFogVisible
        {
            get => _fogController.IsFogVisible;
            set => _fogController.IsFogVisible = value;
        }
    
        private readonly IFogController _fogController;
    }
    
    internal class FogController : BindableBase, IFogController
    {
        public bool IsFogVisible
        {
            get => _isFogVisible;
            set => SetProperty( ref _isFogVisible, value );
        }
    
        private bool _isFogVisible;
    }