如何在 WPF 表单中设置背景图像的图像?

发布于 2024-08-14 17:11:23 字数 79 浏览 6 评论 0原文

在 Windows 窗体中,我会转到“BackgroundImage”并从组合框中选择它。但这里没有这样的财产。

我该怎么办呢?

In Windows Forms, I would go BackgroundImage and just select it from the comboBox. But here there is no such property.

How would I go about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在风中等你 2024-08-21 17:11:23

使用 ImageBrush 作为 Window.Background 属性:

<Window>
  <Window.Background>
    <ImageBrush ImageSource="..." />
  </Window.Background>
</Window>

一般来说,当考虑“如何填充元素或元素的一部分”(无论是窗口背景、文本块前景还是其他)时,答案将是 Brush ,WPF 允许您互换使用实心画笔、渐变画笔、图像画笔、视频画笔或其他画笔。因此,您将寻找统一的Background 和Foreground 属性,而不是像在WinForms 中那样单独的BackgroundColor、BackgroundGradient、BackgroundImage、BackgroundVideo 等属性。

Use an ImageBrush for the Window.Background property:

<Window>
  <Window.Background>
    <ImageBrush ImageSource="..." />
  </Window.Background>
</Window>

In general, when thinking about "how do I fill in an element or part of an element" (whether a window background, a text block foreground, or whatever) the answer will be a Brush, and WPF allows you to interchangeably use a solid brush, gradient brush, image brush, video brush or whatever. So you will be looking for the unified Background and Foreground properties rather than separate BackgroundColor, BackgroundGradient, BackgroundImage, BackgroundVideo etc. properties as you would have done in WinForms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文