New Posts New Posts RSS Feed: WPF Data Verification Errors
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

WPF Data Verification Errors

 Post Reply Post Reply
Author
lars-erik View Drop Down
Newbie
Newbie
Avatar

Joined: 15-Oct-2007
Location: Norway
Posts: 19
Post Options Post Options   Quote lars-erik Quote  Post ReplyReply Direct Link To This Post Topic: WPF Data Verification Errors
    Posted: 30-Jan-2009 at 1:45am

Yes, mee to - I would really like to see an example with WPF validation.

Can you also add an example with validation in  Validation Application Block (VAB)  from Enterprise library 4 ?
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jan-2009 at 11:35am
Originally posted by mbevins1

Greg, are there any examples on how to properly use devforce validation with WPF?

 
Working on one right now, Mike. Coming soon!
Back to Top
mbevins1 View Drop Down
Newbie
Newbie


Joined: 16-Jan-2009
Posts: 27
Post Options Post Options   Quote mbevins1 Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jan-2009 at 9:40am

Greg, are there any examples on how to properly use devforce validation with WPF?

Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jan-2009 at 12:33pm

>> Exception has been thrown by the target of an invocation.

Here’s some text from the discussion of WPF validation in Matthew MacDonald’s book on WPF that may be relevant (p.543):

“If you’re using custom validation rules, you’ll almost certainly choose to place the error information in the ValidationError.ErrorContent propety. If you’re using the ExceptionValidationRule, the ErrorContent property will return the Message property of the corresponding exception. However, there’s a catch. If an exception occurs because the data type cannot be cast to the approprate value, the ErrorContent works as expected and reports the problem. However, if the property setter in the data object throws an exception, this exception is wrapped in a TargetInvocationException, and the ErrorContent provides the text from the TargetInvocationException.Message property, which is the much less helpful warning ‘Exception has been thrown by the target of an invocation.

“Thus, if you’re using your property setters to raise exceptions, you’ll need to add code that checks the InnerException property of the TargetInvocationException. If it’s not null, you can retrieve the original exception object and use its Message property instead of the ValidationError.ErrorContent property.”

 
 
>> Then on a field that is not required and left blank, I am getting this error: Input string was not in a correct format.
 
Don’t have an answer for you on that one, except that I think this error isn’t resulting from an exception thrown by the property setter, but by something at a higher level, maybe associated with a validation defined at the binding level?

Back to Top
mbevins1 View Drop Down
Newbie
Newbie


Joined: 16-Jan-2009
Posts: 27
Post Options Post Options   Quote mbevins1 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Jan-2009 at 5:05am

I am working on trying to get the data verification to work with WPF and cannot seem to figure out how to use the verification built into DevForce.  I currently added the below code to my app.xaml and am getting the notices of errors however, the error messages are not correct.

On a field that is required, I am getting this error:
Exception has been thrown by the target of an invocation.

Then on a field that is not required and left blank, I am getting this error:
Input string was not in a correct format.

Are there any examples on how to use the built in DevForce verification with WPF?

 

Here is what I have in my app file:

        <ControlTemplate x:Key="validationTemplate">

            <DockPanel>

                <TextBlock Margin="5,0,5,0" Foreground="Red" FontSize="16" VerticalAlignment="Center" Text="*" ToolTip="{Binding ElementName=errorAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" />

                <AdornedElementPlaceholder x:Name="errorAdorner" />

            </DockPanel>

        </ControlTemplate>

 

        <Style TargetType="{x:Type TextBox}">

            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource validationTemplate}" />

        </Style>

 

Here is an example of one of my textboxes:

            <TextBox Grid.Column="1" Grid.Row="5" Text="{Binding CurrentVehicle.Description, Mode=TwoWay, UpdateSourceTrigger=LostFocus, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="Auto" Width="Auto" />

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down