0
wpf-mvvm 응용 프로그램이 있습니다.유효성 검사시 원본 개체의 속성을 설정할 수 있습니까?
아래 코드에서 "PartBPremiumBuydown"은 클래스의 인스턴스입니다. 두 개의 속성 => 1. 값을가집니다. 및 2. HasValidationError.
속성 "값"은 텍스트 상자에 바인딩하는 데 사용됩니다. 유효성 검사 오류가있는 경우 ... HasValidationError = true로 설정할 수 있습니까? 사용자가 규칙을 나누기 텍스트로 입력하면 당신이 Value
에 텍스트 상자를 바인딩 할 때, 이제
public string Error { get; private set; }
public string this[string propertyName]
{
get
{
string mError = string.Empty;
if (propertyName == "Value"
&& !<insert your rule>)
{
mError = "Validation error text."
}
Error = mError;
return (string.IsNullOrWhiteSpace(mError))// if NOTHING
? null // then return null
: mError; // else return error
}
}
:
<TextBox ToolTip="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors).CurrentItem.ErrorContent}">
<TextBox.Text>
<Binding Path="PartBPremiumBuydown.Value"
ValidatesOnDataErrors="True"
UpdateSourceTrigger="PropertyChanged"
Converter="{x:Static localns:Converters.DecimalToCurrency}">
<Binding.ValidationRules>
<localns:CurrencyRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
[WPF로 복잡한 비즈니스 데이터 규칙 적용] (http://msdn.microsoft.com/en-us/magazine/ff714593.aspx) –