Different IsEnabled behavior in WPF\Silverlight

Hello,
I had a task to disable a button in WPF which has an image as content.
This task was not a hard competition, but after I disabled the button, the button looked still the same.

image

That’s because the WPF IsEnabled behavior is different than the behavior in Silverlight.

WPF:

The WPF Button control consists of a ContentPresenter wrapped into a Border.

image
If we set IsEnabled to false, the BorderBrush, Background and Foreground of will change. So nothing will be changed, if an image is above all this.
The image color doesn’t gets changed, so the user can not see any difference between enabled or disabled button.
image 

SIlverlight:

The Silverlight button consists of a Border, a ContentPresenter AND 2 Rectangles.
 image

If we disable the button, the following will happen:
image

The rectangle with FIll=”#FFFFFF” will be set to Opacity 0.55 from 0. The result is, we have a grey veil over the button. Will this also happen, if the button has an image as content.

This will look like this: image

How to get the disabled behavior from Silverlight in WPF?

To archieve this, you have to edit the Template from your button.
Create a Copy of the default WPF button and modify it to this.

image

Changes were hightlighed.


Posted Oct 27 2014, 01:58 PM by Holger Vetter
developers.de is a .Net Community Blog powered by daenet GmbH.