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 6049807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:37:05+00:00 2026-05-23T07:37:05+00:00

I have a working WPF dialog that uses DataGrid. The DataGrid is set to

  • 0

I have a working WPF dialog that uses DataGrid. The DataGrid is set to have ItemsSource={Binding SomeCollection, Mode=TwoWay}. This setup works fine, I can read values and update them from UI.

Later I have added Converters to validate values. I show blank when validation fails. Now I am interested in getting the original values back in case if validation fails.

What options do i have here?

  • 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-23T07:37:06+00:00Added an answer on May 23, 2026 at 7:37 am

    I have never used a converter for validation. Instead I use items that implement IDataErrorInfo with an attribute in the databinding attribute for ValidatesOnDataErrors=True.

    Using this method of validation, the original value is retained, and the object returns the errors value (in my case a string saying what the error is). My View’s controls have a custom validation item which adds a red border which fades over time, and a tooltip that pops up on mouse hover.

    Then you just need to put your validation rules in the data classes you are displaying:

    Private Sub OnAddress1Changed()
        Me.RemoveError("Address1")
        If _Address1 Is Nothing OrElse _Address1.Trim = "" Then
            Me.AddError("Address1", "Please enter a valid Address Line")
        End If
        OnPropertyChanged("CanShip")
    End Sub
    
    
    Private m_validationErrors As New Dictionary(Of String, String)
    Private Sub AddError(ByVal ColName As String, ByVal Msg As String)
        If Not m_validationErrors.ContainsKey(ColName) Then
            m_validationErrors.Add(ColName, Msg)
        End If
    End Sub
    Private Sub RemoveError(ByVal ColName As String)
        If m_validationErrors.ContainsKey(ColName) Then
            m_validationErrors.Remove(ColName)
        End If
    End Sub
    
    
    Public ReadOnly Property [Error]() As String Implements System.ComponentModel.IDataErrorInfo.Error
        Get
            If m_validationErrors.Count > 0 Then
                Return "Shipment data is invalid"
            Else
                Return Nothing
            End If
        End Get
    End Property
    
    Default Public ReadOnly Property Item(ByVal columnName As String) As String Implements System.ComponentModel.IDataErrorInfo.Item
        Get
            If m_validationErrors.ContainsKey(columnName) Then
                Return m_validationErrors(columnName).ToString
            Else
                Return Nothing
            End If
        End Get
    End Property
    

    Edit

    And just for the heck of it, I will put an example validation template in to show others how to hook it up.

    <Style x:Key="ToolTipValidation" TargetType="{x:Type Control}">
                                    <Setter Property="Validation.ErrorTemplate">
                                            <Setter.Value>
                                                    <ControlTemplate>
                                                            <Border BorderBrush="Red" BorderThickness="2,1,2,1">
                                                                    <AdornedElementPlaceholder/>
                                                            </Border>
                                                    </ControlTemplate>
                                            </Setter.Value>
                                    </Setter>
                                    <Style.Triggers>
                                            <Trigger Property="Validation.HasError" Value="True">
                                                    <Setter Property="ToolTip" Value="{Binding (Validation.Errors)[0].ErrorContent, RelativeSource={x:Static RelativeSource.Self}}"/>
                                            </Trigger>
                                    </Style.Triggers>
                            </Style>
    

    Finally:
    A MSDN article on implementing Validation

    A video to go with it. Video number 4

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

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
Working in WPF and C#, I have a TransformedBitmap object that I either: Need
I have been working on a WPF Application that is essentially a WYSIWYG editor,
While working in WPF i have the need for a Dynamic Grid. By this
I am working with WPF DataGrid. I have to drag the Column Header, drop
I have a message inspector in my WPF/WCF 4.0 application that is working great
I have a WPF form and I am working with databinding. I get the
I have been working with a string[] array in C# that gets returned from
I have this working definition: IDENTIFIER [a-zA-Z][a-zA-Z0-9]* I don't want to keep repeating the
I have a WPF application that gets installed on the client machine through the

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.