开发者

In WPF, how do I create a dialog-like window (i.e. gray background with no border around the client area)?

开发者 https://www.devze.com 2023-03-25 08:20 出处:网络
I\'m trying to create a simple \'dialog\'-type window in WPF.However, for this specific instance, I do not want the client area to have a border, or even a background for that matter.I just want my co

I'm trying to create a simple 'dialog'-type window in WPF. However, for this specific instance, I do not want the client area to have a border, or even a background for that matter. I just want my controls to appear over the background of the window the way they do with a simple MessageBox.

I played with the different values for WindowStyle but they all called out the client area with a color. I also tried simply setting the client's Background to transparent, but that didn't work either just rendering it in black.

Here's a crappy Photoshop job showing what I'm after:

Note: I'm not after the messagebox contents themselves--e.g. the icon, buttons and message, etc.--I'm 开发者_如何转开发only asking about how to suppress the client area from appearing in any window. I just happened to use a messagebox as an example as someone linked to it in their answer.

In WPF, how do I create a dialog-like window (i.e. gray background with no border around the client area)?

As you can see (or rather can't) there is no visible demarcation of the client area.

Used to be so simple in WinForms, but WPF has me stumped. Anyone?


I'm not sure what you're after. Do you want only the controls on your dialog to be visible with the dialog's border and background transparent? If so, try these settings on your dialog:

WindowStyle="None"
ShowInTaskbar="False"
AllowsTransparency="True"
Background="Transparent"

If you want your dialog's background color to the Winform System.Control with no border, set your form's Background like this (instead of Transparent):

Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号