vendredi 8 février 2019

WPF: bind my CheckBox into my commnd pure XAML

I try to bind my CheckBox into my commnd.

Base view model

public ViewModelBase()
{
    SelectedFileCommand = new SelectedFileCommand(this);
}

<Page.DataContext>
        <viewmodel:ViewModelBase/>
</Page.DataContext>

Command

public class SelectedFileCommand : ICommand
    {
        public event EventHandler CanExecuteChanged;
        public ViewModelBase ViewModel { get; set; }

        public SelectedFileCommand(ViewModelBase viewModel)
        {
            ViewModel = viewModel;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {

        }
    }
}

My CheckBox

<CheckBox IsChecked="{Binding IsSelected}"              
           <i:Interaction.Triggers>
                 <i:EventTrigger EventName="Checked">
                        <i:InvokeCommandAction Command="{Binding SelectedFileCommand}" CommandParameter="{Binding}"/>
                 </i:EventTrigger>
           </i:Interaction.Triggers>
</CheckBox>

I also Try:

<CheckBox DataContext="{Binding}"                                                      
          <i:Interaction.Triggers>
               <i:EventTrigger EventName="IsChecked">
                       <i:InvokeCommandAction Command="{Binding SelectedFileCommand}"
                                              CommandParameter="CheckBox.IsChecked"/>
                </i:EventTrigger>
         </i:Interaction.Triggers>

But my Execute function not called.




Aucun commentaire:

Enregistrer un commentaire