在 WPF 中,如何创建类似对话框的窗口(即客户区域周围没有边框的灰色背景)?
我正在尝试在 WPF 中创建一个简单的“对话框”类型窗口。然而,对于这个特定的实例,我不希望客户区域有边框,甚至不希望有背景。我只希望我的控件像使用简单的 MessageBox 那样显示在窗口的背景上。
我使用了不同的 WindowStyle 值,但它们都用颜色标出了客户区。我还尝试简单地将客户端的背景设置为透明,但这不起作用,只是将其渲染为黑色。
这是一个蹩脚的 Photoshop 作品,显示了我想要的东西:
注意:我不想要消息框内容本身 - 例如图标、按钮和消息,等等--我只是问如何禁止客户区出现在 任何 窗口中。我只是碰巧使用消息框作为示例,因为有人在答案中链接到它。
正如您所看到的(或者更确切地说看不到),客户区没有明显的界限。
以前在 WinForms 中是如此简单,但 WPF 却难倒了我。有人吗?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你在追求什么。您是否希望仅对话框上的控件可见,并且对话框的边框和背景透明?如果是这样,请在对话框中尝试这些设置:
WindowStyle="None"
ShowInTaskbar="False"
允许透明度=“真”
Background="Transparent"
如果您希望对话框的背景颜色为 Winform
System.Control
,没有边框,请像这样设置表单的Background
(而不是透明):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'sBackground
like this (instead of Transparent):