带有背景图像和颜色的网格 [英] Grid with background image and color
问题描述
是否可以在 xaml 中为整个网格同时提供背景图像和颜色?我没有缩放图像,所以有些区域没有颜色.是否可以为网格的其余部分着色?
Is it possible to give an entire grid in xaml both a background image and a color? I am not scaling the image so there are regions that do not have a color. Is it possible to color the rest of the grid in a color?
这是我当前的代码:
<Grid>
<Grid.Background>
<ImageBrush Stretch="None" ImageSource="Images/background_top.png" AlignmentY="Top" AlignmentX="Center"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="50*" />
<RowDefinition Height="50*" />
</Grid.RowDefinitions>
</Grid>
推荐答案
在 WPF 中,如果你想用 VisualBrush 定义一个带有 png 和颜色的画笔,你甚至可以这样做(这个画笔 - 以及相当多的其他画笔是由于渲染画笔时性能下降,在 Windows 应用商店应用程序中不可用)这是一个基本的例子,画笔有很多你可以玩弄的属性:
In WPF you can even do this if you want to define a brush with both a png and color with VisualBrush (this brush - and quite a few other brushes are not available in Windows Store Apps due to performance hit when rendering the brushes) Here is a basic example , the brush has quite a few properties you can play around with:
<Window.Resources>
<VisualBrush x:Key="myBrush">
<VisualBrush.Visual>
<Grid>
<Rectangle Fill="Red"/>
<Image Source="troll.png"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Window.Resources>
<Grid Background="{StaticResource myBrush}"/>
这篇关于带有背景图像和颜色的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!