Pergunta

Eu sou muito iniciante em WPF.Eu tenho a caixa e eu quero que a cada verificação de alterações excecute um comando que fica IsChecked parâmetro e fazer alguma ação.

Eu tenho o seguinte código no meu arquivo XAML:

Na minha viewModel eu tenho o seguinte código:

    private ICommand _addSelectedItemsCommand;
    public ICommand AddSelectedItemsCommand
    {
        get
        {
            if (_addSelectedItemsCommand == null)
            {
                _addSelectedItemsCommand = new RelayCommand(param => this.AddSelectedItems());
            }
            return _addSelectedItemsCommand;
        }
    }


    private void AddSelectedItems()
    {
        Do something...
    }

Mas para "Fazer algo" eu preciso de IsChecked parâmetro, Como posso obtê-lo?

Obrigado

Foi útil?

Solução

Você deve usar InvokeCommandAction de classe.Você pode encontrá-lo no Expression Blend SDK ou você pode simplesmente adicionar este pacote NuGet para o seu projeto.

<CheckBox
  xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="Checked">
      <ei:InvokeCommandAction Command="{Binding AddSelectedItemsCommand}" CommandParameter="..." />
    </i:EventTrigger>
  </i:Interaction.Triggers>
</CheckBox>

Outras dicas

Em Seu ViewModel RelayCommand Parecer

private RelayCommand<string> AddSelectedItemsCommand{get;set;}

E na sua ViewModel Construtor de código parecido

AddSelectedItemsCommand=new RelayCommand<string>(AddSelectedItemsMethod);


void AddSelectedItemsMethod(string AddItem)
{
 Your Code Goes Here.
  }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top