DataWindow validation

Apr 30, 2012 at 5:50 PM

I have a view that inherits from DataWindow and have overridden the ValidateFields method in my view model (which inherits from ViewModelBase).

My view is binding to properties in my view model which are Catel properties.  In my bindings I am setting ValidatesOnDataErrors=True and NotifyOnValidationError=True.

The validation seems to be working properly.  The InfoBarMessageControl is showing all of the error messages and the field borders are red for the properties that are failing validation.  However, I am not seeing the error messages in the tooltips when I hover over the invalid fields.  How do I enable this feature?  The person application sample shows the errors in tooltips.  I'm assuming that the Catel classes are setting the tooltip text somewhere under the covers.

Also, is there a way to hide the InfoBarMessageControl and just use the red borders/tool tips on a DataWindow-derived view?  My window is very small and only has a few fields so the info bar is overkill and, in fact, the full text of the info bar gets cut off since the window is not wide enough.

Coordinator
Apr 30, 2012 at 7:06 PM

For this, you will need to use the StyleHelper. The tooltips are a specific Catel implementation of all controls. You can do this by:

1) First include the resource dictionary in "/Catel.Extensions.Controls;component/themes/generic.xaml"

2) Call StyleHelper.CreateStyleForwarders()

Apr 30, 2012 at 8:34 PM

I added the resource dictionary and called StyleHelper.CreateStyleForwardersForDefaultStyles().  I didn't see a CreateStyleForwarders method.  I'm assuming you meant the one I am calling.

Same result.  InfoBarMessageControl shows the error messages I declared in ValidateFields and red borders are displaying around controls but controls are not displaying tooltips.

Also, can I hide the InfoBarMessageControl (see previous post)?

Coordinator
Apr 30, 2012 at 8:51 PM

Yes, you can hide the InfoBarMessageControl by calling the right base constructor in the datawindow. You should indeed call CreateStyleForwardersForDefaultStyles, my bad. Strange that the tooltips still don't show up. Do they work for you in the examples?

Apr 30, 2012 at 9:25 PM
Edited Apr 30, 2012 at 9:55 PM

Got it.  I was able to hide the InfoBarMessageControl successfully.

Tooltips still not working.  They do work in the examples but as mentioned previously, the examples I have are all for 2.5, not 3.0. 

I went to http://catelexamples.codeplex.com/SourceControl/list/changesets and then clicked Download in the Latest Version section and the projects in that solution are still referencing the Catel.Windows DLL so I know they are not for the 3.0 release.  Should I be downloading a specific changeset?

[Update] I downloaded a specific changeset and now have the examples for 3.0.  The tooltips work for me there and as far as I can see I have things set up the same way as for the PersonApplication example.  But they are still not working in my own project.

Coordinator
May 1, 2012 at 10:25 AM

That's because the latest code is in the 3.0 branch, I forgot to merge them back to the main branch. Just did.Gee

May 3, 2012 at 6:26 PM

I still can't get the tooltips to show for validation errors. 

I created a very small sample app where I have the DataWindow working and I'm certain the generic style is in place because the OK and Cancel buttons are styled correctly.  The InfoBarMessageControl is working as expected so I know the fields are failing validation, but the individual fields do not show a tooltip when I hover over them.

Is there somewhere I can upload my solution so you can review it to see why the tooltips are not displaying?

Coordinator
May 4, 2012 at 3:27 PM

You can create an issue here. Then you can attach files.

May 4, 2012 at 5:59 PM

I finally figured out the issue today.  I had created some styles in my window resources that I was applying to format my controls.  Apparently these styles were overriding the default styles in Catel which is where the tooltips are applied.  I removed my styles and then the tooltips appeared.

I had already created an issue and uploaded my sample project.  You can delete the issue.

I'm still learning WPF.  Is there a way that the default styles defined in Catel can be merged with local styles so I can apply styling to controls without loosing the tooltips?

Coordinator
May 5, 2012 at 2:58 PM

Great, I am glad you found out the issue! And yes, you can use the styles of Catel and customize them, that's the freedom we strive to :)

You can do this by declaring a style like this:

<Style x:Name="MyCustomDefaultTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}" />

In fact, Catel uses this exact same approach when defining the default styles.

The downside of this is that you will have to give the styles a name, otherwise you get circular references (a style with key textbox, based on a style with key textbox, etc). But then again, you can use the StyleHelper like this:

StyleHelper.CreateStyleForwarders("MyCustomDefault");

It will use all styles with the "MyCustomDefault" in front. This way, you can customize the styles on an application wide basis.