I would like to add a semi-transparent colour over the contents of a WPF window (to indicate the state of the window). Currently I am using a UserControl that fills the Window, and I change the Background colour and Visibility as required.
The problem with this method is when the UserControl is visible, I cannot click any controls (Buttons, CheckBoxes) in the Window behind the UserControl. I guess I need to make the UserControl transparent to clicks somehow. Is this possible, or is there a better way to add the colour over the Window?
WPF control's background can be transparent by setting the Background property to null.
To make an element transparent or semi-transparent, you set its Opacity property. A value of 0.0 makes the element completely transparent, while a value of 1.0 makes the element completely opaque.
Opacity in XAML is defined as a double, not an HTML color triplet. http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacity.aspx. You'll want to set it like this: <TextBlock Opacity="0" /> You can also use a brush to set it: <SolidColorBrush Color="#FF295564" Opacity="0.3"/>
You could set IsHitTestVisible
to False
on your masking element.
<Grid>
<Button>Background Button</Button>
<Rectangle Fill="Blue" Opacity="0.25" IsHitTestVisible="False"/>
</Grid>
Try that XAML out in something like Kaxaml. You will still be able to click the button, yet the blue rectangle will be presented over the top. It is semi-transparent due to the low opacity setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With