1

My first time setting "CanExecute" to anything other than "True"... I don't like the default grey background on my button when "CanExecute" is false.

For example I would like to change the background to "Red" if "CanExecute" is "False" (assuming "CanExecute" manipulated the IsEnabled property, which doesn't seem correct). Any advice is appreciated. If there is a good link to get beginner-level answers to this kind of question that would be appreciated too.

I just copied and tried to modify this example, not sure how close it is to being correct:

<Button Content="Update" 
        CommandParameter="{Binding ID}"
        Command="{Binding UpdateCommand}" >
     <Button.Style>
          <Style TargetType="Button">
               <Style.Triggers>
                   <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Background" Value="Red" />
                   </Trigger>
               </Style.Triggers>
           </Style>
     </Button.Style>
</Button>
mjordan
  • 319
  • 2
  • 22
  • 1
    Your logic was correct and your trigger is working; try adding a setter like this inside the trigger: ``. It'll go bold when disabled. The `Background` property is being set -- the problem is that the control template ignores the `Background` property when the button is disabled. You can right click on the button in the XAML designer visual mode and go to "Edit Template". There you'll be able to do what you want. I don't recommend it, though. What your doing will result in an ugly unpleasant and amateurish-looking UI. – 15ee8f99-57ff-4f92-890c-b56153 May 18 '18 at 19:50
  • Possible duplicate of [Background does not change of button C# WPF](https://stackoverflow.com/questions/28346852/background-does-not-change-of-button-c-sharp-wpf) – Tyler Lee May 18 '18 at 21:39
  • Thanks Ed. I did the Edit Template and it's starting to make sense to me! However, when a button is disabled is there a way to make it's background transparent and leave just the content grayed out? – mjordan May 18 '18 at 21:58

0 Answers0