Propertygrid user input data validation issue
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with the supplied WPF reproduction at XctkPropertyGrid and PropertyGrid_Loaded, using the Person and Person2 examples. Trace how PropertyGrid handles IDataErrorInfo and DataAnnotations validation during editing and focus loss. No repository file or test is identified; done means invalid input shows appropriate feedback and the error state clears when the value becomes valid.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
question1: [Range()] causes the UI to have no user error prompts
//test example as follow:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
namespace WpfApp1
{
public class Person: INotifyPropertyChanged, IDataErrorInfo
{
[Required(ErrorMessage = "Name is Required")]
[DisplayName("Name")]
public string Name { set; get; }
[Range(0,150,ErrorMessage = "Age= 0~150")]
[DisplayName("Age")]
public int Age { set; get; }
public event PropertyChangedEventHandler? PropertyChanged;
[Browsable(false)]
public string Error { get; }
public string this[string propertyName]
{
get
{
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentException("Invalid property name", propertyName);
}
string error = string.Empty;
var val = GetType().GetProperty(propertyName).GetValue(this, null);
var results = new List<System.ComponentModel.DataAnnotations.ValidationResult>(1);
var result = Validator.TryValidateProperty(val, new ValidationContext(this, null, null)
{ MemberName = propertyName }, results);
if (!result)
{
var validationResult = results.First();
error = validationResult.ErrorMessage;
}
return error;
}
}
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) => this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if (propertyChanged == null)
return;
propertyChanged((object)this, args);
}
}
}
<xctk:PropertyGrid Name="XctkPropertyGrid" Loaded="PropertyGrid_Loaded"></xctk:PropertyGrid>
private void PropertyGrid_Loaded(object sender, RoutedEventArgs e)
{
Person p = new Person(){Age = 20,Name = "wala"};
this.XctkPropertyGrid.SelectedObject = p;
}
[Range (0150, ErrorMessage="Age=0-150")] can prevent users from entering illegal values, but there is no red box mark or error prompt. Debugging found that this [string propertyName] indexer has not been called because it prevents users from entering illegal values.
question2:use person2 insteadof person1,When the user inputs an incorrect value, a red boder will prompt, but when the user leaves the attribute input box, the value in the red boder will return to the legal value, but the red boder will not disappear.
public class Person2 : INotifyPropertyChanged, IDataErrorInfo
{
[DisplayName("Name")]
public string Name { set; get; }
private int _age;
[DisplayName("Age")]
public int Age {
set
{
if (!ValidataProperty(nameof(Age), value))
return;
_age = value;
RaisePropertyChanged(nameof(Age));
}
get
{
return _age;
}}
public event PropertyChangedEventHandler? PropertyChanged;
[Browsable(false)]
public string Error { get; }
protected bool ValidataProperty(string propertyName, object val)
{
if (propertyName.Equals(nameof(Age)))
{
int ageVal = (int)val;
if (ageVal < 0 || ageVal > 150)
{
ErrorProperty = propertyName;
ErrorMsg = "Age =0~150";
return false;
}
}
ErrorMsg = string.Empty;
ErrorProperty = string.Empty;
return true;
}
private string ErrorProperty;
private string ErrorMsg;
public string this[string propertyName]
{
get
{
if (ErrorProperty.Equals(propertyName))
{
return ErrorMsg;
}
return string.Empty;
}
}
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) => this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if (propertyChanged == null)
return;
propertyChanged((object)this, args);
}
}
- Lingua principale
- C#
- Stelle
- 4.2k
- Fork
- 912
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di xceedsoftware/wpftoolkit
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
xceedsoftware/wpftoolkit#1808 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
xceedsoftware/wpftoolkit#1807 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
xceedsoftware/wpftoolkit#1806 · 1 commento ·
-
Plus Edition. Incorrect window position restoration after returning from the maximized state.Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 45/100
xceedsoftware/wpftoolkit#1804 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
xceedsoftware/wpftoolkit#1802 · 3 commenti ·
Tutte le issue di xceedsoftware/wpftoolkit
Issue simili
-
area-ai untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
dotnet/extensions#7790 ·
I maintainer di solito rispondono entro 1 giorno
-
P2 testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
area-Infrastructure-coreclr os-ios os-maccatalyst os-tvos untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/runtime#134766 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
0 - Backlog Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
BrighterCommand/Brighter#4444 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno