Codelog

foreach(Snippet aSnippet in CodeLog){ aSnippet.GetSolution(); }

Archive for the ‘Window’ tag

Transparent background with opaque controls on top of it in wpf

without comments

Ever felt like having a transparent window background and still opaque controls inside the window? It can be easily done in wpf.

  1. Set the window’s AllowsTransparency to True
  2. Set the window’s Background to Transparent
  3. Add a Rectangle to the parent panel of the window
  4. Set the opacity of the rectangle to some value < 1 (0.7, …)
  5. Add your controls to the parent panel
  6. You are one step away form seeing a transparent background with opaque controls on top of it. Go ahead, run the application now

Sample window,

<Window x:Class=”BackgroundWindow.Transparent.Samples.WPF.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″ AllowsTransparency=”True” Background=”Transparent” WindowStyle=”None”>
<Grid>
<Rectangle Fill=”Gray” Opacity=”0.7″ />
<Button Width=”100″ Height=”100″>Click this on</Button>
</Grid>
</Window>

Written by sudarsanyes

January 13th, 2010 at 9:34 am

Posted in Tips 'n' Tricks, UI, WPF, xaml

Tagged with , , , ,