我在C#中有一段代碼,但無法轉換爲VB.NET。我試過在線轉換器,但VS2008總是給編譯錯誤。任何幫助是極大的讚賞。VB.NET等價於C#代碼
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
什麼編譯錯誤,並在哪些行,你會得到? – ChrisF 2010-07-19 16:54:32
沒有關於您收到的錯誤消息的更深層細節以及哪條線路導致錯誤,我們可能無法爲您提供幫助。 – 2010-07-19 16:58:55
在If Knownbinding.path.path條件檢查後,我在上述代碼中發現錯誤。首先,它不能識別「Do」語句,並且有兩個「End Function」語句,所以在第一個結束語句之後的所有內容都是無效的 – Sai 2010-07-19 16:59:31