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?
Asked
Active
Viewed 237 times
1 Answers
1
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;
}

Haukinger
- 10,420
- 2
- 15
- 28
-
Thanks for the answer @Haukinger, it's pretty clear what you mean, I'm having trouble figuring out how to create a service to which this property redirects to. Could you explain better? – user1804307 Nov 24 '19 at 18:49
-
1Luckily, this is trivially simple. See my edit. Note that the service has to be registered as singleton, of course, because it's meant to be the means of communication between the dialog and the shell for showing and hiding the fog. – Haukinger Nov 25 '19 at 06:39
-
Thanks @Haukinger, works very well! however I hope for a solution built in Prism – user1804307 Nov 25 '19 at 12:57
-
While it would be useful, it might be hard to get it right fully stylable and still easier than just doing it manually. And there are things with a lot higher priority to fix at the `IDialogService`, like being able to show a view model instead of a view. – Haukinger Nov 26 '19 at 07:38