UIVisualizerService event before showing content

Topics: Questions
Oct 13, 2012 at 9:45 AM

Hi Geert,

when the UIVisualizerService creates a (WPF) window,
I have no change to do something between instancing the window and showing it.

Fist I thought the EventHandler<UICompletedEventArgs> completedProc can do this,
but I found out it is called after the window is closed.

I would like to have an loadedProc event handler that can be passed optional
to the IUIVisualizerService.Show method allowing access to both the VM and the View.

IUIVisualizerService.Show(viewModel, (s,e) => DoSomethingBeforeWindowBecomesVisibleWith(e.ViewModel, e.Window))


Oct 14, 2012 at 8:17 PM

Interesting question. Can you give us a real-life scenario. There might be other options, but if there are none, we might consider it.

Oct 15, 2012 at 7:57 AM

Hi geert,

here is my scenario:
In my application the UI is designed using dockable and floating controls like visual studio has.
The layout (shown controls and their position) can be saved and restored using methods on the mainWindows viewModel.

Of course, this works only if the mainView is loaded already.
But in the first stage, the mainVM is instanciated and passed for window creation to the UIVisualizerService.

Until now, I am using the following approach, which leads into a visible main window with (wrong) initial control positions.
Then the layout is loaded and the UI rearranges. I do not like this, the user sees when the controls are rearranged.

var viewModel = new ContactManagement.ViewModels.ContactManagementWindowViewModel();
if (uiVisualizerService.Show(viewModel))

 Instead I would like the following:

var viewModel = new ContactManagement.ViewModels.ContactManagementWindowViewModel();
uiVisualizerService.Show(viewModel), loadedProc:(s,e) => e.ViewModel.RestoreLayout());


Oct 16, 2012 at 10:16 AM

Hi Geert,

on a second (or third?) thought it may be the responsibility of the view to save and restore its layout, isn't it? 
So I put the code in the views codebehind now and trigger it via Window.OnInitialized() and Window.OnClosing().


Oct 18, 2012 at 7:13 AM
Edited Oct 18, 2012 at 7:13 AM

You are right, you should handle this in the view.

If the Window is deriving from the DataWindow, you can easily override OnClosing and OnLoaded.