Skip to content

Instantly share code, notes, and snippets.

@Neccta
Created November 2, 2015 18:25
Show Gist options
  • Save Neccta/5b9bd2eeed29f11f5c2b to your computer and use it in GitHub Desktop.
Save Neccta/5b9bd2eeed29f11f5c2b to your computer and use it in GitHub Desktop.
Returns MahApps Metro Windows for Prism 6.0 Dialogs
using System;
using System.Windows;
using MahApps.Metro.Controls;
using Prism.Interactivity.InteractionRequest;
using Prism.Interactivity;
using Demo.Desktop.Views.Dialogs;
/*
You will need to create your own default windows, you can copy the Prism default windows from
https://github.com/PrismLibrary/Prism/tree/master/Source/Wpf/Prism.Wpf/Interactivity/DefaultPopupWindows
Make sure you change it to a MetroWindow.
*/
namespace Demo.Desktop.Helpers
{
public class WindowDialogHelper : PopupWindowAction
{
protected override Window CreateWindow()
{
return new BaseDialogWindow();
}
protected override Window GetWindow(INotification notification)
{
Window wrapperWindow;
if (WindowContent != null)
{
wrapperWindow = CreateWindow();
if (wrapperWindow == null)
throw new NullReferenceException("CreateWindow cannot return null");
// If the WindowContent does not have its own DataContext, it will inherit this one.
wrapperWindow.DataContext = notification;
wrapperWindow.Title = notification.Title;
PrepareContentForWindow(notification, wrapperWindow);
}
else
{
wrapperWindow = CreateNewDefaultWindow(notification);
}
// If the user provided a Style for a Window we set it as the window's style.
if (WindowStyle != null)
wrapperWindow.Style = WindowStyle;
return wrapperWindow;
}
protected MetroWindow CreateNewDefaultWindow(INotification notification)
{
MetroWindow window;
var confirmation = notification as IConfirmation;
if (confirmation != null)
{
window = new DefaultConfirmationWindow { Confirmation = confirmation };
}
else
{
window = new DefaultNotificationWindow { Notification = notification };
}
return window;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment