我有几个TextBox
绑定属性。这些属性由 Validation.ErrorTemplate 测试。我不使用 MVVM。
我添加了一个按钮来保存我的输入:
<Button Template="{StaticResource BoutonRessourcesTpl}" Command="Save">
<Button.CommandBindings>
<CommandBinding Command="Save" Executed="Save_Executed" CanExecute="Save_CanExecute"/>
</Button.CommandBindings>
<Image Source= "Toolbar_Valider.png" Height="16"/>
</Button>
在我后面的代码中,我写了这个:
private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
{
}
private void Save_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = IsValid(sender as DependencyObject);
}
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));
}
我的问题是我不知道在哪里调用我的代码来保存输入。