The UIVisualizerService allows a developer to show (modal) windows or dialogs without actually referencing a specific view.

The service will automatically determine all windows inside the application domain that implement the DataWindow<TViewModel>. Other windows will have to be registered manually or the NamingConvention property must be set properly.

Available for
WPF / Silverlight / WP7 / WP7 Mango

Test/Emulation service available: yes

Showing a non-modal window
To show a non-modal window, use the following code:

var viewModel = new EmployeeViewModel();

var uiVisualizerService = GetService<IUIVisualizerService>();
uiVisualizerService.Show(viewModel);

Showing a modal window
To show a modal window, use the following code:

var viewModel = new EmployeeViewModel();

var uiVisualizerService = GetService<IUIVisualizerService>();
uiVisualizerService.ShowDialog(viewModel);

Showing a window with callback
To show a (modal or non-modal) window and get a callback as soon as the window is closed, use the following code:

var viewModel = new EmployeeViewModel();

var uiVisualizerService = GetService<IUIVisualizerService>();
uiVisualizerService.Show(viewModel, OnWindowClosed);

Registering a window
To register a custom window which is not automatically detected via reflection, it is required to use the Register method:

var uiVisualizerService = GetService<IUIVisualizerService>();
uiVisualizerService.Register(typeof(EmployeeViewModel), typeof(EmployeeView));

Using the naming convention to find windows
If you use a consistent naming convention for views, it is possible to apply this naming convention to the service. This saves a lot of custom registration. When a window is not registered, the Show window will try to find the view using the naming convention.

To add a naming convention, use the following code:

var uiVisualizerService = GetService<IUIVisualizerService>();
uiVisualizerService.NamingConventions.Add(string.Format("{0}.UI.Windows.{1}Window", NamingConvention.Assembly, NamingConvention.ViewModelName));

The above naming convention will use the following combination:

Input: MyAssembly.UI.ViewModels.EmployeeViewModel
Output: MyAssembly.UI.Windows.EmployeeWindow'

By default, the following naming conventions will be used:
  • /Views/[VM]View.xaml
  • /Views/[VM]Control.xaml
  • /Views/[VM]Page.xaml
  • /Views/[VM]Window.xaml
  • /Controls/[VM]Control.xaml
  • /Pages/[VM]Page.xaml
  • /Windows/[VM]Window.xaml
  • /UI/Views/[VM]View.xaml
  • /UI/Views/[VM]Control.xaml
  • /UI/Views/[VM]Page.xaml
  • /UI/Views/[VM]Window.xaml
  • /UI/Controls/[VM]Control.xaml
  • /UI/Pages/[VM]Page.xaml
  • /UI/Windows/[VM]Window.xaml

Last edited Aug 15, 2011 at 5:08 PM by GeertvanHorrik, version 3

Comments

No comments yet.