gpt4 book ai didi

wpf - 使用ImageBrush的网格背景图像

转载 作者:行者123 更新时间:2023-12-04 13:24:06 24 4
gpt4 key购买 nike

我希望在XAML中使用ImageBrush将背景应用于Grid

我给画笔指定了x:Key,并希望在网格中引用它。

可悲的是,它根本没有将图像作为背景。

<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>

我想我可能以错误的方式提及了它,我尝试了 DynamicResourceStaticResource

最佳答案

在主网格中,您拥有内部子元素,该子元素覆盖了外部网格的所有可用空间,这就是为什么您无法看到背景的原因。

 <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>

只具有可以的宽度,但是高度呢?如果您只是增加高度,那么您的子项将会显示。

或更好地在 child 内部留有利润。

margin =“5”

或使内在 child 透明

不透明度=“0.2”

关于wpf - 使用ImageBrush的网格背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10721603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com