Click here to Skip to main content
12,454,104 members (53,709 online)
Click here to Skip to main content

Stats

147.9K views
1.9K downloads
116 bookmarked
Posted

WPF Business Application Series Part 2 of n - Form Notification Control that Binds to the IDataErrorInfo.Error Property

, 2 Apr 2008 CPOL
WPF VB.NET Business Application Form Notification control that binds to business entity objects that implement the IDataErrorInfo interface. The article also covers entity validation with the WPF 3.5 IDataErrorInfo interface.
WPFLOBPartTwo
Core
Core.csi
Core.vbproj.user
My Project
Themes
WPF
Converters
Custom Controls
CustomToolBarButton
FormNotification
Time Display
Helpers
DemonstrationForms
Business Object
DemonstrationForms.csi
Forms
My Project
WPFBusiessApplicationSample.suo
WPFBusinessApplicationSample
My Project
MyExtensions
Resources
Images
Delete.png
DeleteDisabled.png
New.png
NewDisabled.png
rss.png
rss3d.png
Save.png
SaveDisabled.png
Skins
Metallic
OfficeBlack
OfficeBlue
WPFBusiessApplicationSample.csi
WPFBusiessApplicationSample.vbproj.user
WPFToolBarButtonSample.csi
Core.csi
Core.vbproj.user
DemonstrationForms.csi
Delete.png
DeleteDisabled.png
New.png
NewDisabled.png
rss.png
rss3d.png
Save.png
SaveDisabled.png
WPFBusiessApplicationSample.csi
WPFBusiessApplicationSample.vbproj.user
WPFToolBarButtonSample.csi
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Reflection
Imports System.Text
Imports System.Windows

'WARNING - This is DEMO CODE ONLY.  Please do not code your
'business objects like this.  This is just to get some
'functionality to demo the FormNotification control only.
'
'Future articles will have real business objects and a data access layer
'
Public Class Customer
    Implements INotifyPropertyChanged
    Implements IDataErrorInfo

#Region " Declarations "

    Private _strFirstName As String = String.Empty
    Private _strLastName As String = String.Empty

#End Region

#Region " Events "

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

#End Region

#Region " Properties "

    Public ReadOnly Property [Error]() As String Implements System.ComponentModel.IDataErrorInfo.Error
        Get
            Return Me.CheckProperties(String.Empty)
        End Get
    End Property

    Public Property FirstName() As String
        Get
            Return _strFirstName
        End Get
        Set(ByVal value As String)
            _strFirstName = value
            RaisePropertyChanged("FirstName")
        End Set
    End Property

    Default Public ReadOnly Property Item(ByVal strPropertyName As String) As String Implements System.ComponentModel.IDataErrorInfo.Item
        Get
            Return Me.CheckProperties(strPropertyName)
        End Get
    End Property

    Public Property LastName() As String
        Get
            Return _strLastName
        End Get
        Set(ByVal value As String)
            _strLastName = value
            RaisePropertyChanged("LastName")
        End Set
    End Property

#End Region

#Region " Methods "

    Private Function CheckProperties(ByVal strPropertyName As String) As String

        Dim strResult As String = String.Empty

        If String.IsNullOrEmpty(strPropertyName) OrElse String.Compare(strPropertyName, "FirstName", True) = 0 Then

            If String.IsNullOrEmpty(_strFirstName) Then
                strResult = "First Name is a required field."
            End If

        End If

        If String.IsNullOrEmpty(strPropertyName) OrElse String.Compare(strPropertyName, "LastName", True) = 0 Then

            If String.IsNullOrEmpty(_strLastName) Then

                If strResult.Length <> 0 Then
                    strResult += vbCrLf & vbCrLf
                End If

                strResult += "Last Name is a required field."
            End If

        End If

        Return strResult

    End Function

    Public Function IsValid() As Boolean

        If Me.Error.Length = 0 Then
            Return True

        Else

            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Error"))
            Return False
        End If

    End Function

    Protected Sub RaisePropertyChanged(ByVal strPropertyName As String)

        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(strPropertyName))
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Error"))

    End Sub

#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Karl Shifflett
Architect Infragistics
United States United States

I’m a passionate Platform Architect at Infragistics.

I’m a long-time WPF-Prism fanatic who enjoys writing developer tools and line of business applications.

My current front end passions are: XAML platforms (Xamarin.Forms, Xamarin, UWP, and WPF), Electron, ES2015 (ES6), Node.js, Aurelia, and AngularJS (Angular 1.5.x).

For the back end I use what is appropriate for the project: SQL Server and ASP.NET WebAPI, MongoDB, Express, Azure, Firebase, etc.

I am very pragmatic software engineer and strive to write simple, maintainable, and testable code. Simple code allows for solving complex problems in a maintainable way.

My Blog

My Github Repros

My YouTube Videos

Just a grain of sand on the worlds beaches.


You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 2 Apr 2008
Article Copyright 2008 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid