Improve error message when a user shows a non-Window view as a window

This commit is contained in:
Antony Male 2015-02-17 17:55:38 +00:00
parent 07b61026e9
commit 4b462d28fa
2 changed files with 3 additions and 1 deletions

View File

@ -209,6 +209,7 @@ namespace Stylet
var view = (UIElement)this.ViewFactory(viewType);
// If it doesn't have a code-behind, this won't be called
// We have to use this reflection here, since the InitializeComponent is a method on the View, not on any of its base classes
var initializer = viewType.GetMethod("InitializeComponent", BindingFlags.Public | BindingFlags.Instance);
if (initializer != null)
initializer.Invoke(view, null);

View File

@ -124,7 +124,8 @@ namespace Stylet
var window = view as Window;
if (window == null)
{
var e = new ArgumentException(String.Format("Tried to show {0} as a window, but it isn't a Window", view == null ? "(null)" : view.GetType().Name));
var e = new ArgumentException(String.Format("WindowManager.ShowWindow or .ShowDialog tried to show a View of type '{0}', but that View doesn't derive from the Window class. " +
"Make sure any Views you display derive from Window (not UserControl, etc)", view == null ? "(null)" : view.GetType().Name));
logger.Error(e);
throw e;
}