コントロールのグループの検証をテストするための良い解決策を見ました:
私の Window.xaml.cs で:
private bool IsValid(DependencyObject obj)
{
// The dependency object is valid if it has no errors,
//and all of its children (that are dependency objects) are error-free.
return !Validation.GetHasError(obj) &&
LogicalTreeHelper.GetChildren(obj)
.OfType<DependencyObject>()
.All(child => IsValid(child));
}
私の問題は、私の場合、エラーが発生した場合でも、isValid が常に true を返すことです。xamlのミスが原因だと思いますが...どこですか?
ここに私の Windows.XAML があります:
<Window.Resources>
<CommandBinding x:Key="binding" Command="Save" Executed="Save_Executed" CanExecute="Save_CanExecute" />
</Window.Resources>
<TextBox Name="TextBox_TypeEvenement" Grid.Column="1" VerticalAlignment="Center" Height="20">
<TextBox.Text>
<Binding Path="strEvtType">
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Button Template="{StaticResource BoutonRessourcesTpl}" Command="Save">
<Button.CommandBindings>
<StaticResource ResourceKey="binding"></StaticResource>
</Button.CommandBindings>
<Image Source= "Toolbar_Valider.png" Height="16"/>
</Button>
そして、ここに私の Class.cs c# があります:
private string m_strEvtType;
public string strEvtType
{
get { return m_strEvtType; }
set {
m_strEvtType = value;
if (m_objEvtCode.ReadEvtTypebyType(m_strEvtType) != 0)
{
throw new ApplicationException(m_strEvtType.Trim() + " est innexistant !");
}
FirePropertyChangedEvent("strEvtType");
FirePropertyChangedEvent("m_objEvtCode.strDes");
}
}
isValid が常に true を返す理由がわかりましたか?
どうもありがとう :)
よろしくお願いします :)