Topics: Questions
Mar 21, 2013 at 7:39 AM
In my viewmodel I use Validation

For example:
public string Name
      get { return GetValue<string>(NameProperty); }
      set { SetValue(NameProperty, value); }
In my view I use a usercontrol
<LabelTextBox Text={Binding Name} />
In my the usercontrol LabelTextboxControl I set the ValidatesOnDataErrors and NotifyOnValidationError to true:
           Text="{Binding Text,
                     ElementName=LabelTextBoxControl, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
The Text of LabelTextBoxControl is a DependencyProperty.

The problem is that there is no red border. Only the message in the InfoBarMessageControl

What I'm doing wrong?
Mar 21, 2013 at 7:46 AM
The validation is on the Name property, not on the Text. So you have to add this:

<LabelTextBox Text="{Binding Name, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />

This is because the validation is not implemented on the dependency property, it has no use to put it there.
Mar 21, 2013 at 10:11 AM
Hm. Ok.

So I have to set this propertys in every LabelTextBox. Its also not possible with a style.

Is there no solution to set this for every LabelTextBox?
Mar 22, 2013 at 2:12 PM
Just like you have to set it on every TextBox in WPF. It's normal.
Apr 5, 2013 at 6:06 AM
No. So I hve set it to every LabelTextbox and the red border is on the UserControl. And not only on the Textbox.
I can make a repro. So you can see what I meen.

So I have add it to catelproject.atlassian correct?

Recently i have added an other repro to the issuetracker of codeplex. Do I have to move this to atlassian? Its the last open issue here.
Apr 5, 2013 at 11:50 AM
You can use the ValidationAdorner for this purpose. See the MultiLineInput for an example.

You don't have to put it onto atlassian, that's why I left it open. But trying to load balance all issues with priorities.
Apr 8, 2013 at 7:31 AM
Oh not bad. It works. But only when I set ValidatesOnDataErrors=True on every LabelTextBox. Is there an solution to set it once in the usercontrol.
Apr 8, 2013 at 11:32 AM
Apr 9, 2013 at 6:57 AM
Hello again. Thanks for the link.

The default binding with the dependency property I know. The problem is to set the "ValidatesOnExceptions" Property.

See in the answer: "I don't offhand see a way to set the defaults for NotifyOnValidationError, ValidatesOnDataErrors, or ValidatesOnExceptions"

Ok the other solution "inheriting from the class binding" works. But not very pretty in my opinion. So I have to replace in XAML {Binding} to {namespace:ValidationBinding}

But thats not the problem of catel :-)

So thanks again for your help.
Apr 9, 2013 at 7:13 AM
I think the custom binding is the only way to go. We might include it because it should be fairly simple. You can put it on the backlog if you want.
Apr 9, 2013 at 8:25 AM
I thinks thats not necessary. I thinks its so simple that i can do in my code.

When you do It in catel I have also change the Binding from {Binding} to {catel:SpecialBinding}.

The only thing I don't have to do is the inheriting from the base class "Binding".