Im trying to make a small screenshot program, im making a small WPF window with a border. This should function as a "Viewport" so everything inside the window (within the border) should be screenshottet. How ever when i set the transparency of the window to 0 then i cant see my border. Any ideas on how to make my grid fully transparent, and still preserve a 2 px black border around it?
Asked
Active
Viewed 6,039 times
1 Answers
7
Not sure if you want the window or just the grid transparent with border.
That draws a border around the window:
<Window x:Class="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"
Background="Transparent"
BorderThickness="2"
BorderBrush="Black">
<Grid>
</Grid>
</Window>
This is drawing a broder around the grid only:
<Window x:Class="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" Background="Transparent">
<Border BorderThickness="2" BorderBrush="Black">
<Grid>
</Grid>
</Border>
</Window>

nik
- 1,471
- 1
- 12
- 16
-
Thanks it works, only thing that i did not take into account is that it actually IS transparent, that is, my mouse events are not being fired (dragging the window around) - any ideas? – Brian Hvarregaard Mar 06 '12 at 09:22
-
I struggled with the same problem and decided to do it like eg Snagit does. Doing a full screenshot of the desktop whenever a user starts capturing mode and displaying this screenshot as complete overlay across the whole desktop (also consider multiple monitor environment, so always use VirtualScreen). It's also much better performance wise if you wanna do for example animations like moving the capture rect around the screen. – nik Mar 06 '12 at 09:35