Question: I have a custom control in my WPF application, which has an **Apply** button. When the user clicks the button, I want to execute a command on my view-model (business logic), but also I want to perform some events for the user interface.

It seems to me that if I use the `Command` property, I can't use the `Click` event handler. But, I really don't want to mix my logic together (some of the logic is business logic, some is UI logic). 

For now, I've settled on calling the `ICommand.Execute` method from code behind and using the `Click` event. The problem with this is now I can't take advantage of the `ICommand.CanExecute` method.

```
public class OrderViewModel : ViewModelBase
{
    public DelegateCommand ProcessCommand { get; private set; }

    public void Process(object parameter)
    {
        // Business logic here...
    }
}

<Button Click="OnProcess_Click" />

public void OnProcess_Click(object sender, RoutedEventArgs e)
{
    ViewModel.ProcessCommand.Execute();

    // Do UI specific stuff...
}

```

---

I feel like the way I'm doing it is just bad, especially because I lost the entire `ICommand.CanExecute` benefits, but I'm not sure what else I can do here.

Update: I thought it would be worth mentioning that I prefer that I want my command to execute prior to the UI logic would, not sure if that changes things up.

Answer: 
Because of the way the anonymous inner classes work, it would need to be final. Considering you seem to want to assign this same functionality to each and every row of your list, I believe what you should do is create a class that implements the OnClickListener interface, and holds a reference to the checkBox of which's state the functionality depends on. However, I'm sort of concerned about how many items you have, because if you had many items, this would cause a major memory problem.

So what I thought of just now is, try the following:

```
holder.checkBox1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        CheckBox checkBox = (CheckBox) v;
        if(checkBox.isChecked()){  // I CAN USE THIS

        }
    }
});

```

Because the anonymous class's onClick function is called with the parameter of the View that calls back upon it, therefore the View parameter in this case can only be the CheckBox. I think this is what you need.
If you put `final` in your `holder` object then it will place in the heap.

To reduce some memory going to the heap just use only the boolean from the holder as final instead the whole object.

**example:**

```
holder.nombre_material.setText(entry.getNombreMaterial());
final boolean isChecked = holder.checkBox1.isChecked();

holder.checkBox1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(isChecked ){  

        }

    }
});

```