Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox commanding, check - OK, Uncheck NOT ok, how do i bind the uncheck command?
    primarykey
    data
    text
    <p>I'm having problems attaching an uncheck command to a checkbox. Or more correct, I do not know how to code it. Here's my code for the check command, how should it look to get uncheck also working?</p> <p>View:</p> <pre><code>&lt;CheckBox commands:Checked.Command="{Binding CheckCommand}" IsChecked="False"&gt;&lt;/CheckBox&gt; </code></pre> <p>ViewModel:</p> <pre><code>Private _CheckCommand As DelegateCommand(Of Object) CheckCommand = New DelegateCommand(Of Object)(AddressOf Checked) Private Sub Checked(ByVal parameter As Object) End Sub </code></pre> <p>Command:</p> <pre><code>Public Class ToggleCheckedCommandBehaviour Inherits CommandBehaviorBase(Of CheckBox) Public Sub New(ByVal checkableObject As CheckBox) MyBase.New(checkableObject) AddHandler checkableObject.Checked, AddressOf checkableObject_Checked End Sub Private Sub checkableObject_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) CommandParameter = TargetObject.Name ExecuteCommand() End Sub End Class Public NotInheritable Class Checked Private Sub New() End Sub Private Shared ReadOnly SelectedCommandBehaviorProperty As DependencyProperty = _ DependencyProperty.RegisterAttached("SelectedCommandBehavior", _ GetType(ToggleCheckedCommandBehaviour), _ GetType(Checked), _ Nothing) Private Shared ReadOnly CommandProperty As DependencyProperty = _ DependencyProperty.RegisterAttached("Command", _ GetType(ICommand), _ GetType(Checked), _ New PropertyMetadata(AddressOf OnSetCommandCallback)) Public Shared Sub SetCommand(ByVal CheckBox As CheckBox, ByVal command As ICommand) CheckBox.SetValue(CommandProperty, command) End Sub Public Shared Function GetCommand(ByVal CheckBox As CheckBox) As ICommand Return TryCast(CheckBox.GetValue(CommandProperty), ICommand) End Function Private Shared Sub OnSetCommandCallback(ByVal dependencyObject As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs) Dim CheckBox = TryCast(dependencyObject, CheckBox) If Not CheckBox Is Nothing Then Dim behavior = GetOrCreateBehavior(CheckBox) behavior.Command = TryCast(e.NewValue, ICommand) End If End Sub Private Shared Function GetOrCreateBehavior(ByVal CheckBox As CheckBox) As ToggleCheckedCommandBehaviour Dim behavior = TryCast(CheckBox.GetValue(SelectedCommandBehaviorProperty), ToggleCheckedCommandBehaviour) If behavior Is Nothing Then behavior = New ToggleCheckedCommandBehaviour(CheckBox) CheckBox.SetValue(SelectedCommandBehaviorProperty, behavior) End If Return behavior End Function End Class End Namespace </code></pre> <p>As mentioned the check command works fine, and the command and method connected to it gets fires, what do I need to do to get the uncheck also working? For info I'm using PRISM, CAL, MVVM and SL4 - in VB.NET</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload