samedi 1 juin 2019

CheckBox Command inside a Listview DataTemplate

My CheckBox Command Does not work. I am pretty sure it is because it is within a ListView DataTemplate (since the CheckBox Command works when not inside a Template). Can someone show me how to set this up? If you can explain it to me too that would be great! thanks.

<ListView x:Name="lvReferraSource" ItemsSource="{Binding ReferralSourceTypeObsCollection}" Style="{StaticResource TypeListViewStyle}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <CheckBox x:Name="ckbReferralIsChecked" Content="{Binding Value}" IsChecked="{Binding Active}" Style="{StaticResource CheckBoxStyleBase2}"
                                              Command="{Binding CheckBoxIsChecked}" CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}" >
                                    </CheckBox>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>



private ICommand _CheckBoxIsChecked;
public ICommand CheckBoxIsChecked
    {
        get
        {
            if (_CheckBoxIsChecked == null)
            {
                _CheckBoxIsChecked = new RelayCommand<object>(ExecuteCheckBoxIsChecked, CanExecuteCheckBoxIsChecked);
            }

            return _CheckBoxIsChecked;
        }
    }
    public bool CanExecuteCheckBoxIsChecked(object parameter)
    {
        return true;
    }
    public void ExecuteCheckBoxIsChecked(object parameter)
    {
        Mouse.OverrideCursor = Cursors.Wait;

        if (parameter != null)
        {
            bool isChecked = (bool)parameter;
        }

        Mouse.OverrideCursor = Cursors.Hand;
    }




Aucun commentaire:

Enregistrer un commentaire