如何将 .PNG 图像设置为我的 WPF 表单的 TILED 背景

How to set a .PNG image as a TILED background image for my WPF Form?(如何将 .PNG 图像设置为我的 WPF 表单的 TILED 背景图像?)
本文介绍了如何将 .PNG 图像设置为我的 WPF 表单的 TILED 背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自学 WPF,但我似乎无法找到一种方法来完成这项工作.

I'm learning WPF on my own and I can't seem to find a way to make this work.

这是我的代码:

<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="600" Width="800" >
<DockPanel>
    <Menu DockPanel.Dock="Right"
          Height="30"              
          VerticalAlignment="Top"
          Background="#2E404B"
          BorderThickness="2.6">
        <Menu.BitmapEffect>
            <DropShadowBitmapEffect Direction="270" ShadowDepth="3" Color="#2B3841"/>
        </Menu.BitmapEffect>                          
    </Menu>
</DockPanel>

如何使平铺背景图像出现?

How can I make a tiled background image appear?

推荐答案

或者,也许,您可以使用 视觉画笔:

Or, perhaps, you could use Visual Brush:

<Window
    x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test" Height="600" Width="800">
  <Window.Background>
    <VisualBrush TileMode="Tile" Viewport="0,0,0.5,0.5">
      <VisualBrush.Visual>
        <Image Source="image.png"></Image>
      </VisualBrush.Visual>
    </VisualBrush>
  </Window.Background>
</Window>

Viewport 属性设置基本图块的位置和尺寸.查看此处的示例.

The Viewport property sets the position and dimensions of the base tile. Have a look at examples here.

基本上,0,0,0.5,0.5" 意味着基础图块将占用从点 (0,0) 到 (0.5,0.5) 的空间 - 即从左上角输出区域的角落到中心.(1,1) 是右下角.您应该使用 MSDN Library.这真的很有用.所有的答案都在那里.

Basically, "0,0,0.5,0.5" means that the base tile will take space from point (0,0) to (0.5,0.5) - i.e. from the upper left corner of the output area to centre. (1,1) is the lower right corner. You should make use of MSDN Library. It's really useful. All the answers are there.

这篇关于如何将 .PNG 图像设置为我的 WPF 表单的 TILED 背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)