"ウィンドウ全体とその上のすべてのコントロールを調光"する効果を得ようとしています。WPFで無効なボタンの背景色を変更することはできますか?
ウィンドウとそのすべても無効にする必要があります。
ボタンが無効になっていると、背景色を変更できないように見えるという問題があります。
無効になっていてもボタンの背景色を変更する方法はありますか?
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>
コード:
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);
}
}
}