WPF ExceptionValidationRule not showing in the Validation.Errors Collection -


I'm throwing an ApplicationException if the FirstName value is empty or empty and I'm trying to display the error message in the text block The error is a part of the theme but it always shows "Exception has been put on the target's call"

  public string first name {set {back _firstName;} {set (if String.ISNLORITTE (Value) new application exhaustion Es ( "Frstnem can not be null or empty!"); _firstName = value; OnPropertyChanged ("First"); }} & Lt; Style x: key = "text box style" target type = "text box" & gt; & Lt; Setter Property = "Validation. Error Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate & gt; & Lt; Dockpanel Last Childfill = "True" & gt; & Lt; TextBlock DockPanel.Dock = "Right" Foreground = "Orange" FontSize = "12pt" Text = "{Binding element name = MyAdorner, path = AdornedElement. (Validation.Errors) [0] .ErrorContent}" & gt; & Lt; / TextBlock & gt; & Lt; Border Borderbrush = "Green" BorderTrains = "1" & gt; & Lt; Adoledal placeholder name = "MyOdner" /> & Lt; / Border & gt; & Lt; / DockPanel & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt;  

And finally there is text box control:

  & lt; Text box name = "txtFirstName" style = "{StaticResource TextBoxStyle}" grid. Column = "1" grid. Rows = "0" height = "20" width = "100" margin = "10" & gt; & Lt; TextBox.Text & gt; & Lt; Binding path = "first name" & gt; & Lt; Binding.ValidationRules & gt; & Lt; Exceptional Rule / & gt; & Lt; /Binding.ValidationRules> & Lt; / Binding & gt; & Lt; /TextBox.Text> & Lt; / Text box & gt;  

I went through this the other day, I left an exhausted property And using the verification class.

  & lt; Text box name = "txtFirstName" style = "{static resource text box style}" grid. Column = "1" grid. Line = "0" height = "20" width = "100" margin = "10" & gt; & Lt; TextBox.Text & gt; & Lt; Binding path = "first name" & gt; & Lt; Binding.ValidationRules & gt; & Lt; Validated: StringRange ValidationRaw LowestLeban = "1" MaxLength = "40" Error Message = "Required" /> & Lt; /Binding.ValidationRules> & Lt; / Binding & gt; & Lt; /TextBox.Text>  

Remove the exception from your property so that it just looks like this ...

  private string _firstName; Public string first name {back {back _firstName; } Set {_firstName = value; OnPropertyChanged ("First"); }}  

This is a validation class (I have closed it on the Internet from somewhere) ...

  Public class stringing validation rule: validation rule { Private intimate lengent = 1; Private int _m x length = 1; Private String _ Terror Message; Public int minimum length {mill {return _minimumLength; } Set {_minimumLength = value; }} Public Intl Lightness {{Returns _maximm; } Set {_maximumLength = value; }} Public string error message {get {return_errorMessage; } Set {_errorMessage = value; }} Public override validation result valid (object value, cultureinfo culture infographics) {Validation result result = new verification result (true, empty); String input string = (value? String.Empty). Ostring (); If (inputstring.line and lieutenant; it.Maninum lalenth || (this.maximelmable> gt; 0 & amp; amp; amp; input sting; Lang & gt; this max length)) {Results = New validation result (wrong , This error message); } Return results; }}  

You will need to add a namespace reference to your XML, where the name of the verification class is called the validator (I'm sure you know it, but only for completeness)

Something like this ...

  xmlns: validators = "clr-namespace: wpfApplication1"  

Hope this helps!

Cheers,

Andy


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -