50 % opaque normal window, impossible in WPF?

S

Sin Jeong-hun

With Windows Forms application, just setting the opacity to 0.5 gave
me a 50% opaque normal styled (with the title bar, familiar three
buttons, borders and resizable) window. Did the same thing to a WPF
application, but the window didn't get translucent, instead only the
client area got gray. Then I found I have to set AllowTransparency to
true but then the window style must be set to None to set the
AllowTransparency to true. In short, those translucent normal styled
window, which could be achieved just one line of code in Windows Forms
application, is IMPOSSIBLE in WPF?
 
S

Sin Jeong-hun


In short, those translucent normal styled
window, which could be achieved just one line of code in Windows Forms
application, is IMPOSSIBLE in WPF?

That was my impression when I played around with this, after you posted  
your previous "transparent window" question.

Seems odd, I'd agree.  But that's the conclusion I came to.

Of course, for an expert opinion, you'll probably want to check on  
Microsoft's web-only WPF forum.  Microsoft has apparently decided to  
forego the better user experience and efficiency of newsgroups like this  
one for web-based forums.  That's the only place I know of to reilably  
find the WPF experts (occasionally some read and post here, but this  
newsgroup isn't a very good place for WPF questions generally).

Pete

Thank you for the information. I searched Google for it. By
Microsoft's web-pnly WPF forum, you mean this (http://
forums.msdn.microsoft.com/en-US/wpf/threads/) site right? I'll check
out that forum for WPF issues from now on.
 
P

Pavel Minaev

With Windows Forms application, just setting the opacity to 0.5 gave
me a 50% opaque normal styled (with the title bar, familiar three
buttons, borders and resizable)  window. Did the same thing to a WPF
application, but the window didn't get translucent, instead only the
client area got gray. Then I found I have to set AllowTransparency to
true but then the window style must be set to None to set the
AllowTransparency to true. In short, those translucent normal styled
window, which could be achieved just one line of code in Windows Forms
application, is IMPOSSIBLE in WPF?

It is quite possible. Here's a bit of code that does it:

<Window x:Class="WpfApplication2.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="Green" Opacity="0.5" WindowStyle="None">
<Grid>
<TextBlock>Hello, world!</TextBlock>
</Grid>
</Window>

The only bummer is that you have to have WindowStyle set to "None"...
meaning that you'll have to draw your own title bar and border.
 
P

Pavel Minaev

Sorry, I missed the point where you explicitly say that you want the
titlebar.

Now that is tricky, but one thing that might work is wrapping your
Window into HwndSource as a top-level Win32 window, and applying
WS_EX_LAYERED style to that using P/Invoke.
 
S

Sin Jeong-hun

Seehttp://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx
for an article showing how to simulate the title bar and close button.

Chris Jobson

Thanks. But I have already seen that post before. What I wanted was to
keep Vista's Aero window frame, not implemening my own.
 
S

Sin Jeong-hun

Sorry, I missed the point where you explicitly say that you want the
titlebar.

Now that is tricky, but one thing that might work is wrapping your
Window into HwndSource as a top-level Win32 window, and applying
WS_EX_LAYERED style to that using P/Invoke.

Thanks. That seems to be a solution even though the clue is not
detailed. I'll study for more details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top