WPF Data Validation - Exception, IDataErrorInfo, ValidationRule, & Annotations

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 42

  • @anrodse
    @anrodse 4 года назад +3

    Great explanation! Thank you so much.
    BTW: Thanks for the Ctrl+. tip. I knew it was possible but I didn't know the combination.

  • @ivandrofly
    @ivandrofly Год назад +1

    10:09 I think binding the tooltip directly with the dictionary will throw an exception when there is no error on the property - you only show when there are errors.
    Ps: There is also another interface for validation INotifyOnDataErrroInfo which I think is also very powerful

  • @freddyflares2757
    @freddyflares2757 5 лет назад +1

    I prefer the IDataErrorInfo interface, but an issue in all cases is if you have a Textbox backed by a numeric property with a OneWayToSource binding and the user enters an invalid string. It's not easy to communicate that back to the ViewModel in a Command's CanExecute handler for example. What I did was make a custom ValueConverter that TryParses the string to an int or -1 if error and treat -1 as an invalid value.

  • @kobayashilin3302
    @kobayashilin3302 2 месяца назад

    Really good video, it helps a lot, thank you.

  • @richardkerr2009
    @richardkerr2009 4 года назад +7

    Great explanation and with different implementations - I've ended up using
    a combination of these to fit the needs of my view. Thanks for taking time to put these videos together.

  • @hazemelamir2083
    @hazemelamir2083 5 лет назад +1

    many thanks for your valuable tutorial

  • @vinuhosanagar1
    @vinuhosanagar1 6 лет назад +3

    Thanks much for your tutorials. We need more and more from you :)

    • @ToskersCorner
      @ToskersCorner  6 лет назад +1

      How was the video quality? I just recently realized I had been recording with a downscale to 720p, so in this video I changed to 1080p. Not sure if the extra file size is worth it or not.

    • @vinuhosanagar1
      @vinuhosanagar1 6 лет назад

      ToskersCorner video quality is nice. However getting 720p only

  • @Gazcan
    @Gazcan Год назад

    How can I display the error message in the textbox when using exceptions?

  • @dhruvpanchal9010
    @dhruvpanchal9010 3 года назад

    Great Explanation !

  • @DoctorMGL
    @DoctorMGL 2 года назад

    any way to manage ( *value could not be converted* ) Error message ? that is fired by ( idataErrorinfo )

  • @yeagor541
    @yeagor541 Год назад

    Is there any possibility to also bind button enable/disable status with textblock changing?

  • @lawkaijian618
    @lawkaijian618 Год назад

    Why my OnPropertyChanged got error at IDataErrorInfo?Please help!

  • @hamarasansarharsh
    @hamarasansarharsh 5 лет назад +1

    which one is best performance wise?

  • @surfsoul8660
    @surfsoul8660 3 года назад

    Nice video.
    I have a little question when I tried the ValidationByDataAnnotation method, Unable to cast object of type 'System.Int32' to type 'System.Array' gave me this error, what have I done wrong?

  • @gundolflinda8434
    @gundolflinda8434 4 года назад

    Using the IDataErrorInfo approach together with an ErrorTemplate with seems to work. Am I right that ErrorCollection won't be necessary in this case?

  • @nemethistvan1892
    @nemethistvan1892 5 лет назад

    How can i set the MinimumCharacters field from source code (the value is 5 in the 14:29 picture in the video). I want to set the rule's value from a value what was read out from an xml file at startup.
    I can't solve this huge problem, and it is quite urgent for me.
    Thanks in advance.

  • @erikjansen9149
    @erikjansen9149 4 года назад

    ErrorCollection will keep old messages. Where do you clear the collection?

    • @gundolflinda8434
      @gundolflinda8434 4 года назад

      I firstly thought so aswell. But everytime that "name" validates successfully (i.e. result == null after value of name get checked) we still assign result ( = null ) to ErrorCollection[name], therefore resetting its error message.

  • @Danger418
    @Danger418 5 лет назад

    Is it possible to disable/enable Submit button based on these validation errors?

    • @Trust_Me_Im_An_Engineer
      @Trust_Me_Im_An_Engineer 4 года назад

      Try using a multivalue converter for multiple input fields and then handling the logic inside of the converter.

  • @pk2068
    @pk2068 5 лет назад +4

    well done. Simple, short, clear. No fuss, no wasting time. Tip to the point. And also your english is understandable.

  • @sashabelyy7528
    @sashabelyy7528 2 года назад +2

    14:02 If you wanna property validates on start need set ValidationRule property ValidatesOnTargetUpdate="True". In this case 13:50 need write:

  • @daled3502
    @daled3502 5 лет назад +1

    Are you able to demo the validation being triggered by a button press....

  • @appspointco941
    @appspointco941 3 года назад +1

    Great explanation! Thank you so much.

  • @domeanterai
    @domeanterai 6 лет назад +1

    annotation more simple & clean I think.. good video .. Thanks

  • @hanimajali7581
    @hanimajali7581 2 года назад

    Great Video... I like the annotation because it is like what I use in MVC. Thank you!

  • @billymumby9821
    @billymumby9821 6 лет назад +1

    How would you get access to a validation errors in example 3 in your viewmodel?

    • @ToskersCorner
      @ToskersCorner  6 лет назад

      Can you timestamp that spot to which you are referring?

    • @joshualatusia4858
      @joshualatusia4858 5 лет назад

      @@ToskersCorner I think he means example 3 which starts at 10:39 - The minimum character rule.

  • @andresreloir4076
    @andresreloir4076 5 лет назад

    How would you implement a default validation when using the IDataErrorInfo interface? I would like to avoid a giant switch statement.

  • @solvedplus858
    @solvedplus858 3 года назад

    very cool but how can we bind error collection in ex2 to the error template in ex3?

  • @oussamasethoum2755
    @oussamasethoum2755 3 года назад

    Thank you very much, this is very educative

  • @nandinik7816
    @nandinik7816 3 года назад

    Finally found a good video on validation. Thank you

  • @sergiotardo
    @sergiotardo 4 года назад

    Excelent video!!!! thanks

  • @talkathiriify
    @talkathiriify 5 лет назад

    Thank you very much for all your video series

  • @PaulCuenin
    @PaulCuenin 4 года назад

    very helpful. Thanks

  • @suriyadexter9674
    @suriyadexter9674 4 года назад

    How to do it in the combo box??

  • @longuinni
    @longuinni 6 лет назад +2

    Really nice. I'm learning a lot from you. Keep going, you have a valuable content here.

  • @joshuasafabre1202
    @joshuasafabre1202 5 лет назад

    just thinking. how to clear TextBox After submitting.

    • @Danger418
      @Danger418 5 лет назад +4

      Well the simple way of doing it would be to set the TextBox.Text property to empty in your submit Click Event. Something like this:
      private void btnSubmit_Click(object sender, RoutedEventArgs e)
      {
      txbUsername.Text = "";
      }