У меня есть фрагмент кода в C #, но я не могу конвертировать в VB.NET.Я пробовал онлайн-конвертеры, но VS2008 всегда выдает ошибки компиляции.Любая помощь очень ценится.
foreach (Binding knownBinding in allKnownBindings)
{
string errorMessage = ((IDataErrorInfo)this.DataContext)[knownBinding.Path.Path];
if (errorMessage != null && errorMessage.Length > 0)
{
isValid = false;
// Display the error on any elements bound to the property
FindBindingsRecursively(
this.Parent,
delegate(FrameworkElement element, Binding binding, DependencyProperty dp)
{
if (knownBinding.Path.Path == binding.Path.Path)
{
BindingExpression expression = element.GetBindingExpression(dp);
ValidationError error = new ValidationError(
new ExceptionValidationRule(), expression, errorMessage, null);
System.Windows.Controls.Validation.MarkInvalid(expression, error);
if (_firstInvalidElement == null)
{
_firstInvalidElement = element;
}
return;
}
});
}
}
и эквивалент VB.Net, который я получил:
For Each knownBinding As Binding In allKnownBindings
Dim errorMessage As String = DirectCast(Me.DataContext, IDataErrorInfo)(knownBinding.Path.Path)
If errorMessage IsNot Nothing AndAlso errorMessage.Length > 0 Then
isValid = False
''# Display the error on any elements bound to the property
FindBindingsRecursively(Me.Parent, Function(element As FrameworkElement, binding As Binding, dp As DependencyProperty) Do
If knownBinding.Path.Path = Binding.Path.Path Then
Dim expression As BindingExpression = element.GetBindingExpression(dp)
Dim [error] As New ValidationError(New ExceptionValidationRule(), expression, errorMessage, Nothing)
System.Windows.Controls.Validation.MarkInvalid(expression, [error])
If _firstInvalidElement Is Nothing Then
_firstInvalidElement = element
End If
Return
End If
End Function)
End If
Next