I have a WPF window without Titlebar and border. So I want change windows background based on it is active or not.
I writed code below but I got message Cannot implicitly convert type 'System.Drawing.Brush' to 'System.Windows.Media.Brush'.
Can you help me how to do this? Thank you!
// This function used for both "Actived" and "Deactived" event
private void window_Activated(object sender, EventArgs e)
{
Background = (IsActive)? System.Drawing.SystemBrushes.ActiveCaption :
System.Drawing.SystemBrushes.InactiveCaption;
}
EDIT
Current my windows title bar have Lime color if it active, and gray if inactive, but other user may be diffrent. How can I get these color by code?
Since you're using
WPF, instead of using theSystem.Drawing.SystemBrushesclass you should use the System.Windows.SystemColors class. The brushes from theSystem.Drawingnamespace are not directly compatible with theSystem.Windows.Medianamespace brushes.If you want to use this in your
XAML, you can useEdit based on updated question
If you want to get the theme colour in use, you'll have to use PInvoke. The native method is DwmGetColorizationColor. This will return an integer so you can then create a
SolidColorBrushwith that integer and assign it to your background.That should get your Lime green color.