@ user424096,
que no tienen acceso a mi entorno de Visual Studio, pero a raíz de pseudo código que puede servir de guía para su forma deseada .. .
Crear adjunta de propiedad booleana llamadas NotifySourceUpdates y adjuntar consiste en DataGridCell ... he adjuntado al nivel de cuadrícula de datos para que se aplique a todas las celdas de la cuadrícula de datos ... se puede adjuntar que a nivel de la columna, así ...
<DataGrid ItemsSource="{Binding}">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell" >
<Setter Property="ns:MyAttachedBehavior.NotifySourceUpdates" Value="True"/>
</Style>
</DataGrid.CellStyle>
</DataGrid>
Este comportamiento adjunto controlará el evento adjunto llamado Binding.SourceUpdated a nivel celular. Por lo tanto, siempre que se haya actualizado su fuente de enlace como parte del modo normal o de edición de cualquier elemento de la IU infantil, se activará y saltará al nivel de celda.
public static readonly DependencyProperty NotifySourceUpdatesProperty
= DependencyProperty.RegisterAttached(
"NotifySourceUpdates",
typeof(bool),
typeof(MyAttachedBehavior),
new FrameworkPropertyMetadata(false, OnNotifySourceUpdates)
);
public static void SetNotifySourceUpdates(UIElement element, bool value)
{
element.SetValue(NotifySourceUpdatesProperty, value);
}
public static Boolean GetNotifySourceUpdates(UIElement element)
{
return (bool)element.GetValue(NotifySourceUpdatesProperty);
}
private static void OnNotifySourceUpdates(DependencyObject d, DependencyPropertyEventArgs e)
{
if ((bool)e.NewValue)
{
((DataGridCell)d).AddHandler(Binding.SourceUpdated, OnSourceUpdatedHandler);
}
}
En este controlador de eventos, los eventos son argumentos de DataTransferEventArgs tipo que le da la TargetObject. Este será su control que necesita validar.
private static void OnSourceUpdatedHandler(object obj, DataTransferEventArgs e) //// Please double check this signature
{
var uiElement = e.TargetObject as UIElement;
if (uiElement != null)
{
///... your code to validated uiElement.
}
}
Aquí debe saber qué valor representa el control es válido o no válido.
(uiElement.MyValue == null) //// Invalid!!
Si desea el control de la unión a invalidar, sólo tiene que utilizar la llamada MarkInvalid utilizando estos pasos ...
ValidationError validationError =
new ValidationError(myValidationRule,
uiElement.GetBindingExpression(UIElement.MyValueDependecyProperty));
validationError.ErrorContent = "Value is empty!";
Validation.MarkInvalid(uiElement.GetBindingExpression(UIElement.MyValueDependencyProperty), validationError);
Vamos a saber si esto funciona ...