Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 942279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:14:49+00:00 2026-05-15T22:14:49+00:00

I have a code snippet in C# but unable to convert to VB.NET. I

  • 0

I have a code snippet in C# but unable to convert to VB.NET. I tried online converters but VS2008 always gives compile errors. Any help is greatly appreciated.

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;
            }
        });
    }
}

and the VB.Net equivalent I got is:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:14:50+00:00Added an answer on May 15, 2026 at 10:14 pm

    There are varariables that you need to store in a class in order for the delegate method to have access to them.

    Public Class BindingWork
    ...
    Private binding As Binding
    Private path As String
    Private error_msg As String
    
    Public Sub Start()
    
        Dim errinfo As IDataErrorInfo = CType(Me.DataContext, IDataErrorInfo)
        For Each knownBinding As Binding In allKnownBindings
            error_msg = errinfo(knownBinding.Path.Path)
            If Not String.IsNullOrEmpty(error_msg) Then
                isValid = False
                Me.path = knownBinding.Path.Path
                FindBindingsRecusively(Me.Parent, AddressOf WorkWithBindings)
            End If
        Next
    
    End Sub
    
    Sub WorkWithBindings(ByVal element As FrameworkElement, ByVal binding As Binding, ByVal dp As DependencyProperty)
        If path = binding.Path.Path Then
            Dim expression As BindingExpression = element.GetBindingExpression(dp)
            Dim [error] As New ValidationError(New ExceptionValidationRule(), expression, error_msg, Nothing)
            System.Windows.Controls.Validation.MarkInvalid(expression, [error])
            If _firstInvalidElement Is Nothing Then
                _firstInvalidElement = element
            End If
        End If
    End Sub
    ...
    End Class
    

    Notice your delegate handler uses path, error_msg, _firstInvalidElement and ‘binding’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using the Code Snippet for sending email in VB.Net I have successfully sent an
I have a code snippet written in PHP that pulls a block of text
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
Say I have the following code snippet in c# static const bool DO_PERFORMANCE_CODE =
(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I have a table defined (see code snippet below). How can I add a
We have a project that generates a code snippet that can be used on
Here is a code snippet for an asp:Wizard control I have on an aspx
I have a snippet of code that I'm working with to filter rows in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.