我希望在XAML中使用
ImageBrush
将背景应用到一个Grid
。我已经给brush设置了一个x:Key
,并希望在我的grid中引用它。不幸的是,它根本没有以图像作为背景出现。<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
和StaticResource
。
ImageSource="pack://application:,,,/component/images/bird_text_bg.jpg"
。 - paulc:/myfolder/bird_text_bg.jpg
,它也不会显示出来。 - Luke