在 WPF 图像控件上设置背景图像?
我试图在 WPF 中的图像控件上添加背景图像,例如如果我加载透明 PNG,我仍然可以看到背景。有可能吗,还是微软在 WPF 中完全放弃了这个功能,而我必须依靠 StackPanels/Grids/Whatever 来实现这一点?
I'm trying to have a background image on an image control in WPF, such as if I load a transparent PNG, I would still be able to see the background. Is it possible, or did Microsoft totally drop this feature with WPF and I have to rely on StackPanels/Grids/Whatever to achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Image
没有允许这样做的属性,只需将Image
放在Border
中并设置Border.Background
到ImageBrush
。Image
has no property to allow for that, just put theImage
in aBorder
and set theBorder.Background
to anImageBrush
.不,你需要图像。将Window背景设置为图像并将根元素背景设置为图像
No you need to images. Set the Window background to the image and set the root element background to an image
如此处测试的代码所示,将窗口背景设置为图像画笔。注意 AllowsTransparency="True" 和 WindowStyle="None" 删除边框。
奖励:如果您使用形状,请确保您的表单可拖动
As shown in tested code here set the Window background to an image brush. Notice AllowsTransparency="True" And WindowStyle="None" to drop the border.
Bonus: If you are using a shaped for be sure to make your form draggable