I have a ListView that display a list of CheckBoxes XAML below. The Checkbox is a custom class, the code is below. The initial state of the Checkbox is set correctly. However, when the Checkbox is clicked, it should become disabled (IsEnabled = False), but this doesn't happen, despite having implemented INotify code, shown below, in the custom class (although, I suspect the error is here somewhere, or the XAML markup is wrong). I have even tried to force a binding update on the Click event, but it hasn't helped, code below. Can anyone help?
EDIT: I just realized that the explanation might be a bit disorganized. Here's what should happen: 1) the custom Checkbox is displayed with initial value (this part is working), 2) user clicks the Checkbox, 3) the Click event should fire and update the IsChecked property (it looks like this happens in the debugger when watching the properties), 4) the IsEnabled property switches to False and disables the control (this fails).
XAML:
<DataTemplate>
<CheckBox Content="test"
ToolTip="test"
IsThreeState="False"
x:Name="myCheckBox"
Click="MyClickEvent_OnClicked"
IsChecked="{Binding outIsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
Custom Checkbox:
Public Class MyCustomCheckBox
Inherits CheckBox
Implements INotifyPropertyChanged
Public Property outIsChecked As Boolean
Get
Return Me.IsChecked
End Get
Set(valueChecked As Boolean)
If valueChecked <> Me.IsChecked Then
Me.IsChecked = valueChecked
'NotifyPropertyChanged("IsChecked")
'OnPropertyChanged(New PropertyChangedEventArgs("IsChecked"))
RaisePropertyChanged("IsChecked")
End If
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal inIsChecked As Boolean)
outIsChecked = inIsChecked
End Sub
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Protected Sub RaisePropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
Click Event:
Public Sub MyClickEvent_OnClicked(sender As Object, e As RoutedEventArgs)
Dim cbx1 As ChordPattern = CType(checkboxList(keyIndexes(0)), MyCustomCheckBox)
cbx1.outIsChecked = False
cbx1.IsEnabled = False
'cbx1.GetBindingExpression(MyCustomCheckBox.IsEnabledProperty).UpdateTarget()
End Sub