WPF Window with transparent background containing opaque controls
.net, c#, transparency, user-interface, wpf
Solution
Instead of setting the opacity of the window, set its background's opacity:
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
AllowsTransparency="True" WindowStyle="None">
<Window.Background>
<SolidColorBrush Opacity="0.5" Color="White"/>
</Window.Background>
<Grid>
<Button Width="200" Height="50">button</Button>
</Grid>
</Window>
Problem
I have a window with the following appearance: What I would like, however, is if the `Button` controls (the gray ones with text in the middle) in the `Window`'s main `Grid` had an opacity of 1, totally opaque. As I inherited this project the opacity was set to 0.75 at the top level, inside the opening `Window` tag. Now as I understand this will automatically enforce that on all children and that said children cannot override. How then can I accomplish the transparent background but opaque buttons? The only way I have found so far (as a relative novice in WPF) is to have two separate Windows, one which is the transparent background, and the other has no background but contains the opaque controls. This is terribly hacky though and I want to avoid it if I can. I can supply code if requested, but it is really as simple as a `Window` with windowstyle=none and opacity .75 containing a `Grid`, which contains some very basic `Button` etc controls. Has anyone built such a `Window` before or otherwise have insight into generating one? Thanks.