I have a button whose background is specified by a LinearGradientBrush. I need to disable this button. So, I just set its isEnabled property to "false". But, that removes the background too and since my button doesn’t have a border, what I have left is just the text on the button. Here’s the xaml code for my button:
<Button x:Name="create" Content="Create a new one?" Margin="12, 0, 12, 0" ClickMode="Release" Click="create_click" MinWidth="330" MinHeight="50" BorderThickness="0" Height="110" Foreground="Black">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFA2FC5" Offset="0.279" />
<GradientStop Color="#FF5904A0" Offset="1" />
</LinearGradientBrush>
</Button.Background>
</Button>
And when I set isEnabled to "true" again, the background comes back and everything is good again.
Is this what is supposed to happen?
What should I do if I just want to make the button non-functional for a while without changing its appearance?
You need to edit the appropriate VisualState to change the look of the disabled button. The easiest way to do this is to use Expression Blend.
With the form open, Right click on the button and select Edit Template -< Edit a copy. This will put a chunk of XAML in the page resources section which defines the VisualStates of the control, as well as binding the style of the instance to the newly defined style. The Xaml will look like this…
And the bit you are concerned with is the VisualState element with the name “Disabled”. There is already a background of “Transparent” defined, so you just need to edit that.
If you are doing this manually, you will need to set
Style="{StaticResource ButtonStyle1}"on your button for this to take effect.