About WindowBehavior

Aug 18, 2011 at 7:51 PM

I am testing the WindowBehavior class under Catel 2.0, and have two questions:

1. Showing a modal Window doesn't seem to assign the Owner the way DataWindow does. Am I correct?

2. Instead the DataWindow class, The Window class must be Registered. Again, Am I correct?

If not, may you explain how to

1.Assign the Owner's window

2. Tell me if the Window registration can be bypassed.

Thanks for your support.


Aug 18, 2011 at 7:56 PM

1) Correct. That behavior is part of the DataWindow, and with the Behavior you are choosing *not* to use the DataWindow. The DataWindow is a really powerful class, and in 99% of the time I really recommend to use it. Sometimes however, you are forced to derive from another window and you cannot derive from DataWindow. To still get the powerful MVVM behavior, you can add the behavior, but then all the other luxury of the DataWindow must be implemented manually as well. Maybe it's an idea to add a helper class like DataWindowHelper.AddLuxury(myWindow)


2) In Catel 2.0, the window must be registered. In Catel 2.0, there is a naming convention that is used if the window is not found via DataWindow. In Catel 2.1, we improved the UIVisualizer service so it can contain several naming conventions. We added the following by default:

  • /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

Don't worry if yours is not in there, you can easily add or remove naming conventions. The naming conventions will only be used when the window cannot be found via regular registrations, thus the number of naming conventions does not really affect the overall performance (and once a window is found, it is cached).

If you don't want to use a prebuild version of Catel 2.1 (which I don't see any reason for btw), you have to customize UIVisualizerService.NamingConvention and set it to your naming convention.