I am trying to get the effect of "dimming out the whole window and all controls on it".
The window and everything on it also needs to be disabled.
The problem is that when button is disabled, it doesn't seem to let you change the Background color.
Is there a way in WPF to change the background color of a button even though it is disabled?
XAML:
<Window x:Class="TestDimWindows.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid x:Name="dimElement">
<StackPanel HorizontalAlignment="Left">
<TextBlock
Text="This is an example of dimming a window."
Margin="5"/>
<StackPanel
HorizontalAlignment="Left"
Margin="5">
<Button x:Name="theButton"
Content="Dim the window"
Click="Button_Click"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>
Code Behind:
using System.Windows;
using System.Windows.Media;
namespace TestDimWindows
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
dimElement.Background = new SolidColorBrush(Colors.Gray);
dimElement.Opacity = 0.5;
dimElement.IsEnabled = false;
//I want this button to look "dimmed out" as well
//but since it is disabled, it is a ghostly white.
//how can I change the color even though it is disabled?
theButton.Background = new SolidColorBrush(Colors.Gray);
}
}
}