2016-09-16 39 views
-1

我想实验我的WPF应用程序的图像背景。我下载了一些纹理,但不幸的是我有一个问题。 这里是我的XAML:平铺背景 - 瓦片之间的黑色空间

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="458" Width="473"> 
    <Window.Background> 

     <VisualBrush TileMode="Tile" Viewport="0,0,0.5,0.5" Stretch="None"> 
      <VisualBrush.Visual> 
       <Image Source="Images/binding_dark.png" Stretch="None"> 
        <Image.OpacityMask> 
         <ImageBrush ImageSource="Images/binding_dark.png" Stretch="None" TileMode="Tile"/> 
        </Image.OpacityMask> 
       </Image> 
      </VisualBrush.Visual> 
     </VisualBrush> 
    </Window.Background> 
    <Grid> 

    </Grid> 
</Window> 

这只是一个空的窗口,但是这只是看到更好的问题是什么。 这里的结果: Weird spacings

我想获得一个不错的质感为我的应用程序的背景,但由于某种原因,图像不相互对齐 - 他们之间有这个奇怪的黑色间隔。这是什么原因?

//编辑 只是为了澄清: 我想有许多建在同一图像的平铺副本的背景 - 不是一个imgage填充整个窗口

回答

1

为了让瓷砖背景没有空间之间,你需要要添加:Stretch="Uniform"

此外,您应该将Viewportunits设置为绝对和大小。更改32到图像的大小在下面的代码:

ViewportUnits="Absolute" Viewport="0,0,32,32" 

全码:

<Window.Background> 

<ImageBrush ImageSource="/TestApp;component/Images/bg.png" ViewportUnits="Absolute" Viewport="0,0,32,32" Stretch="Uniform" TileMode="Tile" /> 

</Window.Background> 
0

尝试设置的背景格,不在窗口,像这样:

<Grid> 
    <Grid.Backgroud> 
     <ImageBrush Source="Images/binding_dark.png" x:Name="image" Stretch="UniformToFill"/> 
    </Grid.Background> 
</Grid> 

您可以设置整个窗口的背景,但我不知道这是一个很好的做法

+0

我想你的代码,但它不是我想要得到的结果。我的图像分辨率相当低。我希望有一种相互显示的图像。我不想让一张图片填满整个窗口 - 这种方式看起来像素化。 – Loreno

+0

我也尝试将图片的TileMode设置为“平铺”,但它不会更改任何内容 – Loreno

+0

@Loreno,嗯,有趣,请检查您的图片。它没有透明边框吗?我敢打赌这是一个PNG – Alex