Wpf Validation

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Wpf Validation - Presentation Transcript

    1. WPF Input Validation
      presented by
      Jonathan Birkholz
    2. About Me
      Blogs :
      theabsentmindedcoder.com
      wizardsofsmart.net
      Twitter : RookieOne
      GitHub : github.com/RookieOne
      Email : rookieone@gmail.com
    3. Virtual Brown Bags
      What : Virtual Brown Bags
      An online meeting where the attendees share:
      Tips and tricks
      Tools, shortcuts, articles, books, patterns, languages, you name it
      Experiences
      Things they’ve learned the hard way
      Frustrations or difficulties
      Frustrating issues or difficulties they’re facing that somebody else may be able to help them with
      When : Every Thursday @ 12pm – 1pm
      Where : http://snipr.com/virtualaltnet
      Who : Anyone and Everyone
    4. EPS Consulting
      Custom Software Development
      Consulting / Mentoring
      Training
      WPF
      .NET
      CODE Magazine
      Hiring Developers, PM’s
    5. If you know all this… then feel free to leave
      How to do binding validation with:
      Validation Rules
      Exceptions
      IDataErrorInfo
      Enterprise Library - Validation Application Block
      Markup Extensions
    6. Objective
      Not to tell you how to do input validation with WPF
      Instead just show you a variety of methods available
      In the end, you must decide which methods works best for you
    7. Sample
      App to create a list of party invitees
      Rules for being an Invitee
      Name is required
      Age has to be greater than 18
      Must have a valid email address
    8. Using Validation Rules
    9. Validation Rules
      Validation Rules are the mechanism built into data binding with WPF
    10. Binding – Markup Extension
      Normally you see binding as
      but that is just a binding markup extension.
      We can also set a binding like this
    11. Add Validation Rules to Binding
      Binding needs to Validate on Data Error
      Allows the setting of Validation Rules to Binding
    12. What Validation Rules come with WPF
      • DataErrorValidationRule
      • ExceptionValidationRule
    13. Custom Validation Rules
      Just inherit from Validation Rule
      And override Validate method …
    14. Implement Validate and return ValidationResult
      Fail
      Pass
      Validation Error Message
    15. Required
    16. Greater Than
    17. Regular Expression
    18. Displaying the Errors
    19. Error Template
      Creates the red border
    20. Displaying Error Message
      This is setting the error template we specified
      This trigger sets the tooltip to the error message
    21. Tooltip Conflicts
      Now my normal tooltip shows
      Now I loss my Error Message tooltip
      This is due to how Property values are resolved … Styles, Triggers, local, etc
    22. Using Exceptions
    23. On source…
      Throw exception
    24. On binding…
      Set ValidatesOnExceptions to True
    25. Exception Messages
      Hmm… not exactly the error message we would want…
      And this message is lame…
    26. Using IDataErrorinfo
    27. Implement
    28. On base ViewModel
    29. On Party Invitee View Model
    30. On Binding
      Validates On Data Errors
    31. Works great right?
      Not quite so perfect….
      Bad input… no error
    32. Solution
      Make Age a string
      Change Error Checking
    33. And now…
    34. Enterprise Library
    35. Enterprise Library is
      The Microsoft Enterprise Library is a collection of application blocks designed to assist developers with common enterprise development challenges
      One of which is the Validation Block
    36. You can get EntLib 4.1 here
      http://msdn.microsoft.com/en-us/library/dd203099.aspx
    37. Add Reference
    38. Use Validation Attributes
    39. Error Provider
      Martin Bennedik @
      http://www.bennedik.de/2007/04/wpf-integration-for-validation.html
      Download WPF Validation project
      Has the ErrorProvider control
      The error provider recursively finds all the bindings down the Logical Tree and adds the Enterprise Validation Rule to the bindings
    40. On View
      Wrap bindings to validate with the Error Provider
      Bindings can remain simple
    41. In action
      Not exactly the best out of the box messages…
    42. Setting the Error Message
    43. New and improved
    44. Custom markup extension
    45. Markup Extensions
      The most common markup extensions used in WPF programming are those that support resource references (StaticResource and DynamicResource), and those that support data binding (Binding)
      Static Resource
      Dynamic Resource
      Binding
    46. Custom Markup Extensions
      We can make our own markup extensions
      Use attribute to specify markup extension return type
      Inherit from MarkupExtension
      Implement ProvideValue
    47. Binding Decorator Base
      Philip Sumi @
      http://www.hardcodet.net/2008/04/wpf-custom-binding-class
    48. Base Validation Binding
    49. Required
      Implementation
      Xaml
    50. Greater Than
      Implementation
      Xaml
    51. Email
      Implementation
      Xaml
    52. With Custom Markup Extensions
    53. Conclusion
      We covered how we can do WPF Input Validation with
      Validation Rules
      Exceptions
      IDataErrorInfo
      Enterprise Library Validation Block
      Custom Markup Extensions
    54. Questions
      ?
    55. Git Hub Repository
      http://github.com/RookieOne/WPF-Input-Validation
      Has solution with projects and slide show
      Offered as is
    56. References
      MSDN
      http://msdn.microsoft.com/en-us/library/dd203099.aspx
      Blogs and articles by
      Josh Smith
      Karl Shifflet
      Martin Bennedik
      Philip Sumi
    SlideShare Zeitgeist 2009

    + RookieOneRookieOne Nominate

    custom

    529 views, 0 favs, 0 embeds more stats

    Presentation I gave at the Houston TechFest Sept 20 more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 529
      • 529 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 13
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories