Bogey
Bogey

Reputation: 5734

MahApps Metro DialogCoordinator: Display Dialog to span UserControl only (instead of entire window)?

I'm epxloring different ways to best show dialog windows in my application. MahApp Metro's IDialogCoordinator seems quite useful, but I couldn't quite adjust it to my use case yet.

Say I'm creating a UserControl (view), whose ViewModel needs to be able to display dialogues. These dialogues should, when displayed, overlay/span the UserControl only, NOT the entire Window in which the UserControl is hosted.

Is there any way to achieve this?

Default behavior always seems to span over the entire window, and I haven't found any way to change this yet.

So far, I've been using the Dialog coordinator in a very straightforward way, doing the following in my view:

    <UserControl
         xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
        Dialog:DialogParticipation.Register="{Binding}">

and set set the instance in my view's constructor by,

viewModel.Initialize(DialogCoordinator.Instance);

which I'd then call in the viewmodel via

    IDialogCoordinator _DialogCoordinator;  // set with viewModel.Initialize() called from the view

private async Task _SomeCmdExecute()
    {
      await _DialogCoordinator.ShowMessageAsync(this, "HEADER", "TEST");
    }

Thanks!

Upvotes: 1

Views: 1715

Answers (1)

Thomas Freudenberg
Thomas Freudenberg

Reputation: 5078

Dialogs in MahApps.Metro are always at the window level (see the container PART_MetroActiveDialogContainer in the window's style.)

What you can do is changing the styling of dialogs, so they don't stretch horizontally accross the entire window. See the default template MetroDialogTemplate for reference.

Upvotes: 2

Related Questions