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: 
See [this answer](https://stackoverflow.com/a/4732617/321697) for a detailed description as to why variables referenced in an anonymous inner class must be final. However, in your case there's a simpler solution:

```
holder.checkBox1.setOnClickListener(new View.OnClickListener() {
    @Override public void onClick(View checkBox) {
        if ((Checkable) checkBox).isChecked()) {
            // Do Stuff
        }
    }
}

```

Since the `View` parameter of `OnClickListener` is the actual View that was clicked, and you're setting this listener on the `CheckBox`, you can simply cast the `View` parameter to `Checkable` and reference it from there.

EDIT: Also, you might actually be looking for `CheckBox.OnCheckedChangeListener` rather than `View.OnClickListener`.
Short answer - just copy `ViewHolder` into `final` variable and use it inside `View.OnClickListener`. Like this:

```
final ViewHolder holderRef = holder; 
holder.checkBox1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(holderRef.checkBox1.isChecked()){
        }
    }
});

```

Longer answer - you need to make it final basically due to the way Java manages closures.
You are actually creating an instance of anonymous inner subclass of `OnClickListener` here. Any variables which are used within that class have their values copied in via the autogenerated constructor. So here is another solution you could have - you can explicitly create `OnClickListener` subclass and pass `ViewHolder` reference to it.