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

  Рет қаралды 39,432

ToskersCorner

ToskersCorner

Күн бұрын

In this video we cover creating dat validation in multiples of ways. 1) By throwing an exception, 2) By using the IDataErrorInfo interface, 3)By using custom ValidationRule base class, and 4) By using the System.ComponentModel.Annotations.
I was going to break this video in to multiple parts, but decided to keep it as one video. I advise taking a break half way through if you have a short attention span like me ;)
Link the the GitHub project - github.com/Tosker/ValidationI...
** Tip Jar **
Paypal: toskerscorner@outlook.com
BTC: 3DkvwvcQ8Vt2U84jdtEhNBx2Ueai3Xttmu
ETH: 0xFf79A145e1ED6F538607Ec374968e605cbea758b
BCH: qqpgrnzuhc5hav4e79m8nfhmugs46jtl0ujxcu0tj5
LTC: MHXQmJA3hkwTPeArB9QPNkcLiHQx723yMb

Пікірлер: 41
@pk2068
@pk2068 5 жыл бұрын
well done. Simple, short, clear. No fuss, no wasting time. Tip to the point. And also your english is understandable.
@richardkerr2009
@richardkerr2009 3 жыл бұрын
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.
@anrodse
@anrodse 4 жыл бұрын
Great explanation! Thank you so much. BTW: Thanks for the Ctrl+. tip. I knew it was possible but I didn't know the combination.
@nandinik7816
@nandinik7816 2 жыл бұрын
Finally found a good video on validation. Thank you
@talkathiriify
@talkathiriify 5 жыл бұрын
Thank you very much for all your video series
@appspointco941
@appspointco941 2 жыл бұрын
Great explanation! Thank you so much.
@domeanterai
@domeanterai 6 жыл бұрын
annotation more simple & clean I think.. good video .. Thanks
@hazemelamir2083
@hazemelamir2083 4 жыл бұрын
many thanks for your valuable tutorial
@hanimajali7581
@hanimajali7581 2 жыл бұрын
Great Video... I like the annotation because it is like what I use in MVC. Thank you!
@longuinni
@longuinni 6 жыл бұрын
Really nice. I'm learning a lot from you. Keep going, you have a valuable content here.
@oussamasethoum2755
@oussamasethoum2755 3 жыл бұрын
Thank you very much, this is very educative
@dhruvpanchal9010
@dhruvpanchal9010 3 жыл бұрын
Great Explanation !
@sergiotardo
@sergiotardo 4 жыл бұрын
Excelent video!!!! thanks
@PaulCuenin
@PaulCuenin 4 жыл бұрын
very helpful. Thanks
@vinuhosanagar1
@vinuhosanagar1 6 жыл бұрын
Thanks much for your tutorials. We need more and more from you :)
@ToskersCorner
@ToskersCorner 6 жыл бұрын
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
@sashabelyy7528
@sashabelyy7528 2 жыл бұрын
14:02 If you wanna property validates on start need set ValidationRule property ValidatesOnTargetUpdate="True". In this case 13:50 need write:
@ivandrofly
@ivandrofly Жыл бұрын
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 жыл бұрын
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.
@andresreloir4076
@andresreloir4076 5 жыл бұрын
How would you implement a default validation when using the IDataErrorInfo interface? I would like to avoid a giant switch statement.
@hamarasansarharsh
@hamarasansarharsh 5 жыл бұрын
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?
@solvedplus858
@solvedplus858 3 жыл бұрын
very cool but how can we bind error collection in ex2 to the error template in ex3?
@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?
@daled3502
@daled3502 4 жыл бұрын
Are you able to demo the validation being triggered by a button press....
@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.
@yeagor541
@yeagor541 Жыл бұрын
Is there any possibility to also bind button enable/disable status with textblock changing?
@billymumby9821
@billymumby9821 5 жыл бұрын
How would you get access to a validation errors in example 3 in your viewmodel?
@ToskersCorner
@ToskersCorner 5 жыл бұрын
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.
@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.
@Gazcan
@Gazcan Жыл бұрын
How can I display the error message in the textbox when using exceptions?
@DoctorMGL
@DoctorMGL 2 жыл бұрын
any way to manage ( *value could not be converted* ) Error message ? that is fired by ( idataErrorinfo )
@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.
@suriyadexter9674
@suriyadexter9674 4 жыл бұрын
How to do it in the combo box??
@lawkaijian618
@lawkaijian618 Жыл бұрын
Why my OnPropertyChanged got error at IDataErrorInfo?Please help!
@joshuasafabre1202
@joshuasafabre1202 5 жыл бұрын
just thinking. how to clear TextBox After submitting.
@Danger418
@Danger418 5 жыл бұрын
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 = ""; }
WPF in C# with MVVM using Caliburn Micro
1:23:30
IAmTimCorey
Рет қаралды 361 М.
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 14 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 81 МЛН
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 46 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 6 МЛН
How to Implement Validation in WPF MVVM
47:07
Tactic Devs
Рет қаралды 6 М.
WPF Dependency Injecting W/ Ninject
16:02
ToskersCorner
Рет қаралды 13 М.
Feedback (Loading, Validation, Error Messages) - WPF MVVM TUTORIAL #8
19:49
WPF Controls with MVVM: ItemsControl
33:34
IAmTimCorey
Рет қаралды 82 М.
Уроки WPF. Таблицы и списки
15:45
Программирование - это просто
Рет қаралды 49 М.
WPF Custom Dialogs - Part 2 [Dialog Controls]
12:22
ToskersCorner
Рет қаралды 11 М.
IDataErrorInfo Interface in WPF
13:09
DotNetSkoool
Рет қаралды 23 М.
SimpleWPF - WPF Library, Navigation, templating, commanding.
10:13
ToskersCorner
Рет қаралды 4,8 М.
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 81 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 247 М.
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 14 МЛН