WPF - DatePicker Selected Date Validation Rule - wpf

I have been working on this problem for a while now, I would like to add a validation rule to my DatePicker that will make sure the SelectedDate is between two dates (Upper and Lower limits).
I would also like these two limits to be data bound to other elements, the example I am working with an employee cannot have a birth date before they joined a company for eg.
Here are my classes:
LimitDates:
Public Class LimitDates
Inherits DependencyObject
Public Shared ReadOnly UpperLimitDateProperty As DependencyProperty
Public Shared ReadOnly LowerLimitDateProperty As DependencyProperty
Shared Sub New()
Dim metadata As New FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.None)
UpperLimitDateProperty = DependencyProperty.Register("UpperLimitDate", GetType(Date), GetType(LimitDates))
LowerLimitDateProperty = DependencyProperty.Register("LowerLimitDate", GetType(Date), GetType(LimitDates))
End Sub
Public Property UpperLimitDate As Nullable(Of DateTime)
Get
Return CType(GetValue(UpperLimitDateProperty), Nullable(Of DateTime))
End Get
Set(value As Nullable(Of DateTime))
SetValue(UpperLimitDateProperty, value)
End Set
End Property
Public Property LowerLimitDate As Nullable(Of DateTime)
Get
Return CType(GetValue(LowerLimitDateProperty), Nullable(Of DateTime))
End Get
Set(value As Nullable(Of DateTime))
SetValue(LowerLimitDateProperty, value)
End Set
End Property
End Class
DateValidationRule:
Public Class DateValidationRule
Inherits ValidationRule
Public Property FutureDateAllowed As Boolean = True
Public Property LimitDates As LimitDates
Public Overloads Overrides Function Validate(value As Object, cultureInfo As CultureInfo) As Windows.Controls.ValidationResult
Try
Dim d As Date = CDate(value)
If Not FutureDateAllowed And d > Now Then
Return New System.Windows.Controls.ValidationResult(False, "Future dates not allowed")
End If
If Not LimitDates Is Nothing Then
If Not LimitDates.LowerLimitDate Is Nothing Then
If d < LimitDates.LowerLimitDate Then
Return New System.Windows.Controls.ValidationResult(False, "Date must less then " & LimitDates.LowerLimitDate)
End If
End If
If Not LimitDates.UpperLimitDate Is Nothing Then
If d > LimitDates.UpperLimitDate Then
Return New System.Windows.Controls.ValidationResult(False, "Date must not be behond " & LimitDates.UpperLimitDate)
End If
End If
End If
Catch ex As Exception
Return New System.Windows.Controls.ValidationResult(False, "Not in correct format, please input a correct date. Eg. 23-04-2012")
End Try
' If hasn't returned an error already, must be okay
Return New System.Windows.Controls.ValidationResult(True, Nothing)
End Function
End Class
And XAML markup for EmployeeView:
<Label Style="{StaticResource EditViewLabel}" Grid.Row="0">Birth Date</Label>
<DatePicker Grid.Row="0" Grid.Column="1" x:Name="dtPkBirthDate" DisplayDateEnd="{Binding ElementName=dtPkStartDate, Path=SelectedDate}">
<DatePicker.SelectedDate>
<Binding Path="Employee.DateOfBirth">
<Binding.ValidationRules>
<local:DateValidationRule FutureDateAllowed="True">
<local:DateValidationRule.LimitDates>
<local:LimitDates UpperLimitDate="4/5/2010" />
</local:DateValidationRule.LimitDates>
</local:DateValidationRule>
</Binding.ValidationRules>
</Binding>
</DatePicker.SelectedDate>
</DatePicker>
It all looks fine to me, and it does work if the date is hard coded, but when I try binding to another control or to a property of the DataContext, the Limit date value is never set, only the default value of 12:00AM appears in the debugger.
Also how can I set and check if dates are null (VB.net not C# with I am used to)?
Thanks.
Luke
Edit:
Okay so I think I might have worked out a little bit of why, after reading Binding ElementName. Does it use Visual Tree or Logical Tree and http://social.msdn.microsoft.com/Forums/vstudio/en-US/e359b99f-e864-4e9e-b81e-2692f240598f/binding-to-object-in-template-in-another-visual-tree?forum=wpf I think that the binding on DateValidationRule might not be finding the ElementName as both element's are siblings and so in a different visual tree..?
I will keep researching

Yup, I'm going with my answer I found... it's impossible!
"ValidationRule is not a dependency object (nor is it in the element tree), so you cannot set bindings on dependency properties on it (nor would they be resolved if you could)." MSDN
I've moved on to using the Infragistics XamDateTimeInput (Which says it's for Silverlight but is also here for WPF). Still doesn't have the validation I want, but I am happy using Value Converters and Business Logic validation.
Thanks

Related

Detect, whether an exception occured when using "ValidatesOnExceptions"

Imagine a WPF project with an MVVM approach. So, there is a view and a view model.
In the view model I have a property, that might throw an exception in the setter.
Public Property DateValue As Nullable(Of Date)
Get
Return _dateValue
End Get
Set(value As Nullable(Of Date))
If value.HasValue Then
If value.Value < Date.Today Then
Throw New Exception("Error Message")
End If
End If
_dateValue = value
'skipped NotifyPropertyChanged in this example for the sake of simplicity
End Set
End Property
In the view there is a control bound to this property. And since I like to see my exceptions I switched on ValidatesOnExceptions in the binding and add an ErrorTemplate.
...
<DatePicker SelectedDate="{Binding DateValue, ValidatesOnExceptions=True}"
SelectedDateFormat="Short"
Validation.ErrorTemplate="{StaticResource ErrorTemplate}" />
...
Since you can't reset the value of a DatePicker once you picked one (at least I don't know how to do that) I added a small reset button right next to the DatePicker which is bound to a command which sets the property DateValue of the view model to Nothing. And since I don't want to see this button all the time I bound its Visibility to DateValue.HasValue, so this button only shows, when there's a value to reset.
So far, so good.
But now I have a problem when I pick an invalid date in the DatePicker (one that throws an exception in the properties' setter).
My reset button doesn't show up, since there's no value in the bound property, and I can't reset the DatePicker any other way (at least not that I know of). I'd first have to pick a proper date before I can reset the whole thing.
So, is there any way to determine, whether my property setter threw an exception. There must be a way, since this very error is shown to the user.
Or do I have to manually remember, that I threw an exception in another variable, to be able to access this information when needed?
And how do I "clear" the DatePicker. Since there's no value in the property, setting the property to Nothing will not change anything in the view. How would I get rid of the error?
Class ViewModel
Inherits INotifyPropertyChanged
Private selectedDate As DateTime
Public Property SelectedDate As DateTime
Get
Return Me.selectedDate
End Get
Set(ByVal value As DateTime)
If value < DateTime.Today Then
Throw New ArgumentException("Date can't be in the past.")
End If
Me.selectedDate = value
OnPropertyChanged()
End Set
End Property
Public ReadOnly Property ResetDateCommand As ICommand
Get
Return New RelayCommand(AddressOf ExecuteResetDate)
End Get
End Property
Public Sub New()
Me.SelectedDate = DateTime.Today
End Sub
Public Sub ExecuteResetDate(ByVal commandParameter As Object)
Return CSharpImpl.__Assign(Me.SelectedDate, DateTime.Today)
End Sub
End Class
MainWindow.xaml
<Window>
<Window.Resources>
<ViewModel />
</Window.Resources>
<StackPanel x:Name="RootPanel" viewModels:Item.IsMarkedAsRead="True">
<Button Content="Reset Date"
Visibility="{Binding ElementName=DatePicker, Path=(Validation.HasError), Converter={StaticResource BooleanToVisibilityConverter}}"
Command="{Binding ResetDateCommand}" />
<DatePicker x:Name="DatePicker"
SelectedDate="{Binding SelectedDate, ValidatesOnExceptions=True}"
SelectedDateFormat="Short" />
</StackPanel>
</Window>
Remarks
It's best practice in UI design that you always prevent wrong input. If possible you shouldn't allow invalid input e.g. by disabling buttons, hiding invalid options, limiting ranges etc.
Don't allow the user to select invalid options. This leads to a frustrating user experience. One way to prevent wrong input is to use specialized controls. Instead of forcing the user to type a date you offer a DatePicker. This eliminates typos. But it can also eliminate wrong selections by providing only valid dates.
If you want to disallow selecting dates of the past you can narrow down the selectable range:
<!-- Only show dates from today -->
<DatePicker DisplayDateStart="{x:Static system:DateTime.Today}" />
If you have additional illegal dates e.g. holidays you can define a collection of those dates by setting the DatePicker.BlackoutDates property:
DatePickerHelper.cs
Class DatePickerHelper
Inherits DependencyObject
Public Shared ReadOnly BlackedDaysProperty As DependencyProperty = DependencyProperty.RegisterAttached("BlackedDays", GetType(IEnumerable(Of CalendarDateRange)), GetType(DatePickerHelper), New PropertyMetadata(Nothing, AddressOf DatePickerHelper.OnBlackDatesChanged))
Public Shared Sub SetBlackedDays(ByVal attachingElement As DependencyObject, ByVal value As IEnumerable(Of CalendarDateRange))
Return attachingElement.SetValue(DatePickerHelper.BlackedDaysProperty, value)
End Sub
Public Shared Function GetBlackedDays(ByVal attachingElement As DependencyObject) As IEnumerable(Of CalendarDateRange)
Return CType(attachingElement.GetValue(DatePickerHelper.BlackedDaysProperty), IEnumerable(Of CalendarDateRange))
End Function
Private Shared ReadOnly Property DatePickerTable As Dictionary(Of INotifyCollectionChanged, DatePicker)
Private Shared Sub New()
DatePickerHelper.DatePickerTable = New Dictionary(Of INotifyCollectionChanged, DatePicker)()
End Sub
Private Shared Sub OnBlackDatesChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim attachedDatePicker = TryCast(d, DatePicker)
Dim oldObservableCollection As INotifyCollectionChanged = Nothing
If CSharpImpl.__Assign(oldObservableCollection, TryCast(e.OldValue, INotifyCollectionChanged)) IsNot Nothing Then
oldObservableCollection.CollectionChanged -= AddressOf UpdateDatePickerBlockedDates
DatePickerHelper.DatePickerTable.Remove(oldObservableCollection)
End If
Dim newObservableCollection As INotifyCollectionChanged = Nothing
If CSharpImpl.__Assign(newObservableCollection, TryCast(e.NewValue, INotifyCollectionChanged)) IsNot Nothing Then
newObservableCollection.CollectionChanged += AddressOf UpdateDatePickerBlockedDates
DatePickerHelper.DatePickerTable.Add(newObservableCollection, attachedDatePicker)
End If
attachedDatePicker.BlackoutDates.AddRange(TryCast(e.NewValue, IEnumerable(Of CalendarDateRange)))
End Sub
Private Shared Sub UpdateDatePickerBlockedDates(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
Dim attachedDatePicker As DatePicker = Nothing
If Not DatePickerHelper.DatePickerTable.TryGetValue(TryCast(sender, INotifyCollectionChanged), attachedDatePicker) Then
Return
End If
Select Case e.Action
Case NotifyCollectionChangedAction.Add
attachedDatePicker.BlackoutDates.AddRange(e.NewItems.OfType(Of CalendarDateRange)())
Case NotifyCollectionChangedAction.Remove, NotifyCollectionChangedAction.Replace
e.OldItems.OfType(Of CalendarDateRange)().ToList().ForEach(Function(removedItem) attachedDatePicker.BlackoutDates.Remove(removedItem))
Case NotifyCollectionChangedAction.Move
Case NotifyCollectionChangedAction.Reset
attachedDatePicker.BlackoutDates.Clear()
Case Else
End Select
End Sub
End Class
ViewModel.cs
Class ViewModel
Public Property BlockedDates As ObservableCollection(Of CalendarDateRange)
// Block Christmas holidays and all days in the past
Public Sub New()
Return CSharpImpl.__Assign(Me.BlockedDates, New ObservableCollection(Of CalendarDateRange) From {
New CalendarDateRange(New DateTime(2020, 12, 24), New DateTime(2020, 12, 26)),
New CalendarDateRange(DateTime.MinValue, DateTime.Today.Subtract(TimeSpan.FromDays(1)))
})
End Sub
End Class
MainWindow.xaml
<!-- Only show dates from today -->
<DatePicker DatePickerHelper.BlackedDays="{Binding BlockedDates}" />

WPF INotifyErrorInfo Validation.Error Event Not Raising

I'm encountering a strange problem. Despite setting everything correctly, the Validation.Error doesn't get fired.
Here are the details:
<DataTemplate x:Key="dtLateComers">
<TextBox Text="{Binding ParticipantTag, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, NotifyOnSourceUpdated=True}" Validation.Error="Validation_Error" >
</DataTemplate>
Code behind (VB.Net) to set ItemsSource of HeaderedItemsControl:
hicLateComers.ItemsSource = _LateComersViewModels
_LateComersViewModels is ObservableCollection(Of ParticipantViewModel)
Implementation of ParticipantViewMode:
Public Class ParticipantViewModel
Implements INotifyPropertyChanged, IDataErrorInfo
Private _ParticipantTag As String = ""
Public Property ParticipantTag() As String
Get
Return _ParticipantTag
End Get
Set(ByVal value As String)
_ParticipantTag = value
_ParticipantTag= _ParticipantTag.ToUpper
NotifyPropertyChanged("ParticipantTag")
End Set
End Property
Public ReadOnly Property Item(byVal columnName As String) As String Implements IDataErrorInfo.Item
Get
Dim errorString As String = String.Empty
If columnName.Equals("ParticipantTag") Then
If not ParticipantValidationManager.IsValidKeypadTag(_ParticipantTag, True) then
errorString = "Incorrect entry. Please try again."
End If
End If
Return errorString
End Get
End Property
Public ReadOnly Property [Error] As String Implements IDataErrorInfo.Error
Get
Throw New NotImplementedException()
End Get
End Property
End Class
Problem
When I set ItemSource property (as mentioned above in code), Item index is called as many times as there are items in _LaterComersViewModels. Validation works and as a result I get red circle next to TextBox. However, Validation_Error never gets fired until I start typing in Textbox. Typing in TextBox changes the Property binds to it and validate it. Base on validation Validation.Error event is raised, and handled by application. Within that event handler I maintain a count of errors.
So the Question is, why Validation.Error doesn't get raised when one/more items fail on a validation rule during initial data binding? Though it does get raised once property is changed by typing into that TextBox.
Feel free to share any idea, assumption or a solution. Any type of help will be appreciated. Thanks.
Side note: I've a simple C# application which doesn't use data templating. In that application, Validation.Error event gets raised perfectly on start, and on property change. Though in that application, Model is binding to DataContext property of Grid.
Since Validation.Error is an attached event, you could hook up the event handler on the HeaderedItemsControl:
<HeaderedItemsControl x:Name="hicLateComers" ItemTemplate="{StaticResource dtLateComers}" Validation.Error="Validation_Error" />
The result should be pretty much the same since you can easily access both the TextBox and the ParticipantViewModel object in the event handler:
Private Sub Validation_Error(sender As Object, e As ValidationErrorEventArgs)
Dim textBox = CType(e.OriginalSource, TextBox)
Dim participant = CType(textBox.DataContext, ParticipantViewModel)
'...
End Sub

Converting normal property to dependency property

I have a control that I am using for my new application. This control has a regular property as such.
Public Property Value() As String
Get
If AutoCompleteTextBox.SearchText Is Nothing Then
Return String.Empty
Else
Return AutoCompleteTextBox.SearchText.ToString.Trim
End If
End Get
Set(value As String)
AutoCompleteTextBox.SearchText = value
End Set
End Property
Edit:
So, after multiple tries, I am finally at this stage.
Public Shared ValueProperty As DependencyProperty = DependencyProperty.Register("Value", GetType(String), GetType(AutoCompleteBox))
Public Property Value() As String
Get
Return Me.GetValue(ValueProperty).ToString
End Get
Set(value As String)
Me.SetValue(ValueProperty, value)
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
This is the dependency property. This property is still not binding. No errors are shown in output window for binding.
Text="{Binding RelativeSource={RelativeSource Self}, Path=Value, Mode=TwoWay}"
This is my binding method. I have no idea what else I can do. At least if there was an error, I could have figured out something. Without any error, I am just a headless chicken here.
Please refer to the following url for all the dependency fundamentals
http://www.wpftutorial.net/dependencyproperties.html
Basically, you can get a property changed event of dependency property by providing a FrameworkPropertyMetadata.
new FrameworkPropertyMetadata( [Default Value],
OnCurrentTimePropertyChanged);
And you can get back the target control (DependencyObject) at the event handler and implement your logic over there
private static void OnCurrentTimePropertyChanged(DependencyObject source,
DependencyPropertyChangedEventArgs e)
{
AutoCompleteTextBox control = source as AutoCompleteTextBox;
string time = (string)e.NewValue;
// Put some update logic here...
}
Declaring a dependency property in a control is a good thing.
You could make some binding in the xaml (sorry I don't have your XAML - I imagine).
Something like :
<TextBox x:Name="AutoCompleteTextBox"
Text="{Binding RelativeSource={RelativeSource=Self},Path=Value}"/>
Regards
TextBox has a property called Text. When you access Text property it will give you text entered in TextBox. Same is your case. Now why you want to convert it into a DP ? A DP would be useful if you want o bind this DP to some other control.
Extend this control itself. Make a new control and introduce this new DP.
While a DP is used where you want to bind this property to some control. This property then gets updated from control or control gets updated from this DP depending upon binding mode set.
How to do binding :
<TextBox x:Name="UserInput" />
<uc:MyAutoCompleteTextBox ValueDP="{Binding Text, ElementName=UserInput, Mode=OneWay}" />
MyAutoCompleteTextBox is new control which extends(inherits) from your old AutoComplete control.
If you want to apply some filtering logic or anything else, you can apply it in your DP itself like this :
Get
someVariable = TryCast(Me.GetValue(ValueProperty), String)
' apply somg logic to someVariable
' use your old Value property from here
Return someVariable
End Get
There are many WPF Binding tutorials on net.
I recommend :
http://blog.scottlogic.com/2012/04/05/everything-you-wanted-to-know-about-databinding-in-wpf-silverlight-and-wp7-part-one.html
Just change your code with following code and you should be good
your code
Public Shared ReadOnly ValueProperty As DependencyProperty = DependencyProperty.Register("Value", GetType(String), GetType(AutoCompleteBox))
Public Property Value() As String
Get
Return TryCast(Me.GetValue(ValueProperty), String)
End Get
Set(value As String)
Me.SetValue(ValueProperty, value)
End Set
End Property
New code
Public Shared ReadOnly ValueProperty As DependencyProperty = DependencyProperty.Register("Value", GetType(String), GetType(AutoCompleteBox))
Public Property Value() As String
Get
If AutoCompleteTextBox.SearchText Is Nothing Then
Return String.Empty
Else
Return AutoCompleteTextBox.SearchText.ToString.Trim
End If
End Get
Set(value As String)
AutoCompleteTextBox.SearchText = value
End Set
End Property
This DP will do what your Older property was doing. But just think about your requirement there can be a better way of writing the things.
Thanks

How to make the command property of a wpf button a dependency property of a user control

I am trying to teach myself the basics of creating user controls in wpf. To that end I have been experimenting with building a data navigation control to allow navigation through the records being retrieved by various view models. My long term plan is for a completely self contained custom control, but I'd like to master the smaller points first so to that end I'd like to know how I can make the Command, and Command Parameter properties ( as well as the Is Enabled property) of buttons that form part of my user control dependency properties of the user control itself.
I have succeeded to make the various image and image height and width properties of the various buttons dependency properties of the overall user control but thus far have not had any success with the Command, Command Parameter and is Enabled properties.
I'd welcome any suggestions anyone could proffer.
I have the following already (I set for each button in my user control):
#Region "Next Button"
Public Property ImageNext() As ImageSource
Get
Return DirectCast(GetValue(ImageNextProperty), ImageSource)
End Get
Set(value As ImageSource)
SetValue(ImageNextProperty, value)
End Set
End Property
Public Shared ReadOnly ImageNextProperty As DependencyProperty = DependencyProperty.Register("ImageNext", GetType(ImageSource), GetType(DataNavigator), New UIPropertyMetadata(Nothing))
Public Property ImageNextWidth() As Double
Get
Return CDbl(GetValue(ImageNextWidthProperty))
End Get
Set(value As Double)
SetValue(ImageNextWidthProperty, value)
End Set
End Property
Public Shared ReadOnly ImageNextWidthProperty As DependencyProperty = DependencyProperty.Register("ImageNextWidth", GetType(Double), GetType(DataNavigator), New UIPropertyMetadata(16.0))
Public Property ImageNextHeight() As Double
Get
Return CDbl(GetValue(ImageNextHeightProperty))
End Get
Set(value As Double)
SetValue(ImageNextHeightProperty, value)
End Set
End Property
Public Shared ReadOnly ImageNextHeightProperty As DependencyProperty = DependencyProperty.Register("ImageNextHeight", GetType(Double), GetType(DataNavigator), New UIPropertyMetadata(16.0))
This however has been adding properties to standard wpf buttons, now what I want to do is access properties of those buttons that already exist and bind to them (via my user control) from my viewmodels
It is the same as any other dependency property.
You declare the DP like this:
Public Shared ReadOnly ThisCommandProperty As DependencyProperty = _
DependencyProperty.Register("ThisCommand", GetType(ICommand), _
GetType(thiscontrol), Nothing)
Public Property ThisCommand As ICommand
Get
Return CType(GetValue(ThisCommandProperty), ICommand)
End Get
Set(ByVal value As ICommand)
SetValue(ThisCommandProperty, value)
End Set
End Property
and in the XAML of your user control:
<UserControl ...>
<Button Command={Binding ThisCommand} ... />
</UserControl>
You set the parameter in the same way, but with type object, and you have to cast it so the correct type in your command handler.
When you use the UserControl, it is like this:
<local:thisControl ThisCommand={Binding whateverCommandYouWantToBindTo},
ThisCommandParameter={Binding whateverParameterYouWant)>
It is really just the same as any other DP, except for the type. Of course, whateverCommandYouWantToBindTo has to be set up as an ICommand too.
People might also tell you that defining usercontrols is bad and to use templates instead, and it's probably a better approach in most cases. But if you want to learn about DPs, I say learn.
Here is an example that I have working in front of me:
Public Shared ReadOnly EditButtonCommandProperty As DependencyProperty = _
DependencyProperty.Register("EditButtonCommand", _
GetType(ICommand), GetType(PersonListControl), Nothing)
Public Property EditButtonCommand As ICommand
Get
Return CType(GetValue(EditButtonCommandProperty), ICommand)
End Get
Set(ByVal value As ICommand)
SetValue(EditButtonCommandProperty, value)
End Set
End Property
Public Shared ReadOnly EditButtonCommandParameterProperty As DependencyProperty = _
DependencyProperty.Register("EditButtonCommandParameter", GetType(Object), _
GetType(PersonListControl), Nothing);
Public Property EditButtonCommandParameter As Object
Get
Return CType(GetValue(EditButtonCommandParameterProperty), Object)
End Get
Set(ByVal value As Object)
SetValue(EditButtonCommandParameterProperty, value)
End Set
End Property
And in the UserControl XAML:
<StackPanel>
<ListBox ... />
<Button
...
Command="{Binding EditButtonCommand}"
CommandParameter="{Binding EditButtonCommandParameter}"/>
</StackPanel>
And I use this UserControl like this:
<local:PersonListControl
...
EditButtonCommand="{Binding PersonListEditCommand}"
EditButtonCommandParameter="{Binding Parents}"/>

WPF INotifyPropertyChanged not allowing null value

Using WPF and EF and new to both. I may use the wrong terminology.
Using the EF wizard and code generators, I set up an EF using several tables, one of which is a lookup table.
I set up a form with a datagrid for the user to edit items in this lookup table. An issue I'm having is that the user can edit a cell, then close the form, but the editing of the cell will not update the underlying SQL database. I researched INotifyPropertyChanged and it seemed to be what I needed.
I implemented INotifyPropertyChanged to class bound to the datagrid. Before the implementation, the datagrid displayed all null values. After implementation, a message displays when the first null value is read that a nullable object must have a value.
Code:
Public Property ProcedureName As String
Get
Return _ProcedureName
End Get
Set(value As String)
_ProcedureName = value
RaisePropertyChanged("ProcedureName")
End Set
End Property
Private _ProcedureName As String
The exception occurs at "_ProcedureName = value".
Entire class:
Imports System
Imports System.Collections.ObjectModel
Partial Public Class tlkpProcedures_PartB
Inherits PropertyChangedBase
Public Property CPT As String
Get
Return _CPT
End Get
Set(value As String)
_CPT = value
RaisePropertyChanged("CPT")
End Set
End Property
Private _CPT As String
Public Property ProcedureName As String
Get
Return _ProcedureName
End Get
Set(value As String)
_ProcedureName = value
RaisePropertyChanged("ProcedureName")
End Set
End Property
Private _ProcedureName As String
Public Property BillingAmount As Nullable(Of Decimal)
Get
Return _BillingAmount
End Get
Set(value As Nullable(Of Decimal))
_BillingAmount = value
RaisePropertyChanged("BillingAmount")
End Set
End Property
Private _BillingAmount As Decimal
Public Property UniqueID As Integer
Public Overridable Property tblBilling_PartB As ObservableCollection(Of tblBilling_PartB) = New ObservableCollection(Of tblBilling_PartB)
End Class
Any help or advice is appreciated.
I'm not very good at VB but it seems like you try to assign a Nullable ( value As Nullable(Of Decimal) ) to a non-nullable (Private _BillingAmount As Decimal).
You should either cast value as Decimal or define _BillingAmount as Nullable(Of Decimal).

Resources