Fix WindowManager bug

This commit is contained in:
Antony Male 2014-02-26 08:31:01 +00:00
parent a6cfd64031
commit 75311f3d30
1 changed files with 9 additions and 8 deletions

View File

@ -32,29 +32,30 @@ namespace Stylet
{ {
var viewManager = IoC.Get<IViewManager>(); var viewManager = IoC.Get<IViewManager>();
var view = viewManager.LocateViewForModel(viewModel) as Window; var view = viewManager.LocateViewForModel(viewModel);
if (view == null) var window = view as Window;
if (window == null)
throw new Exception(String.Format("Tried to show {0} as a window, but it isn't a Window", view.GetType().Name)); throw new Exception(String.Format("Tried to show {0} as a window, but it isn't a Window", view.GetType().Name));
viewManager.BindViewToModel(view, viewModel); viewManager.BindViewToModel(window, viewModel);
var haveDisplayName = viewModel as IHaveDisplayName; var haveDisplayName = viewModel as IHaveDisplayName;
if (haveDisplayName != null) if (haveDisplayName != null)
{ {
var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay };
view.SetBinding(Window.TitleProperty, binding); window.SetBinding(Window.TitleProperty, binding);
} }
if (isDialog) if (isDialog)
{ {
var owner = this.InferOwnerOf(view); var owner = this.InferOwnerOf(window);
if (owner != null) if (owner != null)
view.Owner = owner; window.Owner = owner;
} }
new WindowConductor(view, viewModel); new WindowConductor(window, viewModel);
return view; return window;
} }
private Window InferOwnerOf(Window window) private Window InferOwnerOf(Window window)