AvaloniaCommunity/Prism.Avalonia

Custom Window for dialogs

cirrusone opened this issue · 2 comments

Great project, thank you.

Are there any samples showing how to use a custom Window to host a dialog rather than the inbuilt Prism.Avalonia/Services/Dialogs/DialogWindow.axaml?

I can see IDialogService allows passing name of the hosting window registered but I haven't been able to get this working using

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.Register<MainWindow>();
        containerRegistry.Register<CustomMainWindow>(); // Not working CustomMainWindow.axaml?
        containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>();
        containerRegistry.RegisterDialog<DialogView, DialogViewModel>();
    }

It would be useful to be able to style the parent window inline with the main application (eg ExtendClientAreaToDecorationsHint="True"). I can see there is a similar open issue relating to style Add dialog style Settings #84 but custom window would be more useful in certain situations

You need to register a DialogWindow using the RegisterDialogWindow method like this:
containerRegistry.RegisterDialogWindow<CustomMainWindow>();
, or provide a name if you don't want to override the default dialog window.
Make sure your window implements IDialogWindow like this:
class CustomMainWindow : Window, IDialogWindow
Btw, take a look at this Style definition if you want to have a consistent look for your application's windows.

Excellent, thank you. I was close but needed to add IDialogWindow and the corresponding interface method IDialogResult? to the custom window.