DataWindow 3.0 issues

Apr 27, 2012 at 5:31 PM

I am trying to use a DataWindow in Catel 3.0 and have run into a few minor issues:

1.  I right-click on my Views folder and then click Add and then New Item.  In the Add New Item dialog I select Catel under Installed Templates and then Window (WPF with Catel, logic in view base) on the right.  I give it the appropriate name and click Add.

I immediately get an error indicating an invalid namespace.  In the xaml, a namespace entry has been included for:  xmlns:ViewModels="clr-namespace:MedicalLog.Views.ViewModels"

The correct namespace should be just MedicalLog.ViewModels.  Is this a bug or am I doing something wrong?  Correcting the namespace fixes the error.

2. The created Window inherits from DataWindow<SettingsViewModel> but when I build I'm getting a warning indicating that this class is obsolete and that I should use the non-generic DataWindow class instead.  Is there a newer version of the template that doesn't use the obsolete class?

I changed it so that the class inherits from DataWindow instead and removed the x:TypeArguments="ViewModels.SettingsViewModel" entry from the xaml and then was able to build without getting the warning.  If the non-generic DataWindow is used, it seems that the ViewModels namespace entry that caused the first issue is no longer necessary.

3.  When I run the app and open the view, the OK and Cancel buttons appear at the left bottom of the form and are sized to fit their contents instead of being the same size which looks odd.  In the documentation, it indicates that the buttons are supposed to be same-sized and right-aligned.  Has this changed?  The documentation also indicates that styles are available but I couldn't find any examples of how to use them.  If you could let me know how to do that I would appreciate it.


Apr 27, 2012 at 5:49 PM

Also, is there a way to specify commands for the DataWindow buttons?  I couldn't figure that out from the documentation or sample.  I would like to have a specific command execute when OK is clicked, for example.

Apr 27, 2012 at 5:52 PM

1) I know, really frustrating, the item templates don't give you access to the real folder where you add the item to. I have tried all options available, nothing contains the right value, so we cannot fix this without MS.

2) If you install the latest code snippets and templates, the item should derive from the non-generic base (DataWindow, not DataWindow<SettingsViewModel), which should also fix point 1.

3) If the buttons appear on the left bottom, you have not included the styles. Try adding the right resource dictionary in your app.xaml.

Apr 27, 2012 at 8:26 PM

About the specific commands: no, there is not for the default buttons. In this case, you need to specify custom window mode, and then add the Ok and Cancel manually. Isn't overriding Save in the view model enough?

Apr 28, 2012 at 6:06 PM

Re: adding resource dictionary - are there instructions on how to do that?  I didn't see that in the documentation.  Sorry if I missed it.

Apr 28, 2012 at 6:07 PM

If I can override Save in the view model that will suffice.  Sorry, I must have missed that.

Apr 29, 2012 at 2:18 PM

Yes, the Save method is there just for your custom logic. Internally Catel uses IViewModel.SaveViewModel so you can't break anything when overriding Save. We tried to make it all as flexible as possible.

You can add a resource dictionary as described here. Using the style forwarders is up to you, referencing the resource dictionary is enough for the datawindow.

Apr 30, 2012 at 3:02 PM

Awesome!  Thanks for the assistance.

Apr 30, 2012 at 4:31 PM
Edited Apr 30, 2012 at 4:47 PM

I followed the instructions in the link but the OK and Cancel buttons are still on the left and not uniformly sized.  Is there some other step I might be missing?  Also, is there a way to edit the style to say, for example, change the button size or margins? 

Here is what I have done so far:

1.  Created a view that inherits from DataWindow.

2.  Added resource dictionary to App.xaml per the instructions in the documentation.  The only difference was that I had to provide a key for the resource dictionary which was not part of the example.  I used x:Key="Catel".

3.  Added a call to Catel.Windows.StyleHelper.CreateStyleForwardersForDefaultStyles in the App OnStartup method.

4.  Using IUIVisualizerService to instantiate the view.



It appears that the project is unable to find the resource dictionary which is why it isn't working.  I noticed that the sample application has a reference to a Catel.Windows DLL but I am using Catel.MVVM which has a Catel.Windows namespace in it.  I updated the resource dictionary entry to Source="/Catel.MVVM;component/themes/generic.xaml" and now I am not getting an error saying it can't find the resource dictionary but the buttons are still not correct.

Apr 30, 2012 at 7:04 PM

Catel.Windows does no longer exists, it's pre 3.0. You should try to use the Catel.Extensions.Controls for the generic theme.

Apr 30, 2012 at 7:53 PM

I updated my App.xaml resource dictionary entry to Source="/Catel.Extensions/Controls;component/themes/generic.xaml".  Is that what you meant?  That did not resolve the issue either.

Are there any sample projects that are written for Catel 3.0?  All of the ones I have seem to be for 2.5 which is cause for confusion.

Apr 30, 2012 at 7:56 PM

Strange, should work. All examples in the Catel.Examples repository are Catel 3.0. Can you try these to see if it looks ok there?

Apr 30, 2012 at 8:17 PM

I found my issue.  I had defined some application-level styles that were in the Application.Resources section of my App.xaml.  Once I moved them inside the outer ResourceDictionary tag it started working.  I'm new to WPF and didn't realize that was a problem.  Sorry for the false alarm.