Disabling Button Click According To Template IsEnabled Value

244 views Asked by At

I have a Button that I give it a control template style of a CheckBox.

See the following code:

<Style x:Key="radButtonCheakBoxStyle" TargetType="{x:Type telerik:RadButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type telerik:RadButton}">
                <CheckBox Content="{Binding ., 
Converter={StaticResource ContentConverter}}" 
Command="{TemplateBinding Property=Command}" 
IsEnabled="{Binding State,Converter={StaticResource CommandStateConverter}}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The problem is that even when the CheckBox is disabled, and in the UI it is really disabled, the Button click still works, so when I press the disabled CheckBox I still get to the command.

How can I prevent this?

1

There are 1 answers

2
jnovo On BEST ANSWER

Have you tried binding the Button.IsEnabled property too?

As an alternative - which I'd recommend - you can disable the command by implementing the CanExecute method so that it returns false whenever you want it disabled (probably the same logic you have located in your CommandStateConverter).