Friday, August 24, 2012

Caliburn Micro: configuring the Window dialog

Caliburn Micro offers you the WindowManager to display a dialog. You only have to specify the viewmodel and Caliburn will do the rest, it finds the corresponding usercontrol, embeds this usercontrol into a window, binds view and viewmodel together and shows the result to the user.var loginViewModel = new LoginViewModel(); 


WindowManager windowManager = new WindowManager(); 
SettingsViewModel vm=new SettingsViewModel();
windowManager.ShowDialog(vm); 

But what if you want to change the behavior or the look of this window? As Caliburn.Micro creates this window for you, you don’t have direct control over it.

Therefore the WindowManager.ShowDialog method has an extra overload which allows you to specify a settings object (as a Dictionary<string,object>).

How can we use this? An example…

dynamic settings = new ExpandoObject(); 
settings.WindowStyle = WindowStyle.ToolWindow; 
settings.ShowInTaskbar = true; 
settings.Title = "This is a custom title"; 
 
windowManager.ShowDialog(loginViewModel, null, settings); 

No comments: