使用的ImageBrush网格背景图片 [英] Grid Background Image using ImageBrush
问题描述
我希望使用的ImageBrush
在XAML到后台应用到电网
。
I wish to use an ImageBrush
in XAML to apply a background to a Grid
.
我给刷一个 X:键
并要提到它在我的网
I've given the brush a x:Key
and want to refer to it in my grid.
可悲的是,它并没有拿出图像作为背景的。
Sadly, it doesn't come up with the image as a background at all.
<Window.Resources>
<ImageBrush ImageSource="/MAQButtonTest;component/images/bird_text_bg.jpg" x:Key="BackgroundSponge" />
<Style TargetType="TextBlock">
<Setter Property="OverridesDefaultStyle" Value="True"/>
</Style>
<ControlTemplate TargetType="Button" x:Key="ButtonTemplate">
<Grid Width="444" ShowGridLines="False" SnapsToDevicePixels="True" Background="{DynamicResource BackgroundSponge}">
<Grid.RowDefinitions>
<RowDefinition Height="51" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#286c97">
</Grid>
<Grid Grid.Row="1" Background="#5898c0">
<ContentPresenter Grid.Row="0" />
</Grid>
</Grid>
</ControlTemplate>
</Window.Resources>
我想我可能指的是它走错了路,我试过 DynamicResource
和静态资源
推荐答案
在你的主网架你有涵盖所有外网的可用空间,这就是为什么你不会能够看到背景。孩子的内心
In your main grid you have inner childs which cover all the available space of outer grid thats why you wont be able to see the background.
<Grid Width="444"
Height="500"
Background="{DynamicResource BackgroundSponge}"
ShowGridLines="False"
SnapsToDevicePixels="True">
<Grid.RowDefinitions>
<RowDefinition Height="51" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#286c97" Opacity="0.2" Margin="5"/>
<Grid Grid.Row="1" Background="#5898c0" Opacity="0.2" Margin="5">
<ContentPresenter Grid.Row="0" />
</Grid>
</Grid>
时,只具有宽度是好的,但怎么样的高度。如果你只是让高度较大那么你的子项就会显示出来。
is having only width which is ok but what about the height. if your just make height larger then your child items it will shows up.
或最好是有保证金里面的孩子的。
or better to have margin in inside childs.
保证金=5
或使内在的小孩透明仿
不透明度=0.2
这篇关于使用的ImageBrush网格背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!