From 4b462d28fa636f7f2a046dfde318899ff0cd0930 Mon Sep 17 00:00:00 2001 From: Antony Male Date: Tue, 17 Feb 2015 17:55:38 +0000 Subject: [PATCH] Improve error message when a user shows a non-Window view as a window --- Stylet/ViewManager.cs | 1 + Stylet/WindowManager.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Stylet/ViewManager.cs b/Stylet/ViewManager.cs index d7cc285..5a44b34 100644 --- a/Stylet/ViewManager.cs +++ b/Stylet/ViewManager.cs @@ -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); diff --git a/Stylet/WindowManager.cs b/Stylet/WindowManager.cs index a3260a6..f92e1e0 100644 --- a/Stylet/WindowManager.cs +++ b/Stylet/WindowManager.cs @@ -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; }