0

I would like to gray out the image only instead of the entire button. The reason being is that the image on the button is partly transparent, so when the entire button is grayed out it just looks odd.

In the below image you can see the entire button is grayed out instead of just the visible image

fully grayed out button

related... sorta: Disabling Button with custom Content in Silverlight?

Community
  • 1
  • 1
TruthOf42
  • 2,017
  • 4
  • 23
  • 38

1 Answers1

0

You will need to override the ControlTemplate for your button. How to do that?

  1. Create a new style
  2. In that style define the ControlTemplate
  3. ControlTemplate find the definition for the visual state named "Disabled"
  4. Change that so that it changes the image only, without greying out the entire button.

These are the relevant parts of your controls template

<ControlTemplate TargetType="Button">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <!-- other states go here -->
            <VisualState x:Name="Disabled">
                <Storyboard>
                    <DoubleAnimation Duration="0" 
                                     Storyboard.TargetName="DisabledImage"  
                                     Storyboard.TargetProperty="Opacity" To="1"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <!-- rest of the template goes here -->
</ControlTemplate>

The DisabledImage you reference in the visual state manager then would need to cover the image displayed on an enabled button entirely, so that when disabled, only the greyed out image is visible to the user.

Spontifixus
  • 6,570
  • 9
  • 45
  • 63