图片为 window 样式背景未加载 wpf

Imge to window style background not loading wpf

我是 WPF 的新手,在阅读了一些关于将图像放入我的 window 背景的文章后,我仍然无法让它工作。有人能告诉我我做错了什么吗? 我的 groceryLog.jpg 设置为 Resource 并在 Copy to output[=17] 上设置了“Copy if newer” =]. 我的 app.xaml

<!--Buttons - it works -->
    <LinearGradientBrush x:Key="ButtonBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="Cornsilk" Offset="0"/>
        <GradientStop Color="Aquamarine" Offset="1"/>
    </LinearGradientBrush >
    <SolidColorBrush x:Key="ButtonBorderBrush" Color="Blue"/>
    <Style TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border Name="Border"
                                Background="{StaticResource ButtonBackgroundBrush}"
                                BorderBrush="{StaticResource ButtonBorderBrush}"
                                BorderThickness="1" CornerRadius="4">
                        <Grid>
                            <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Border" Property="Background"
                                Value="DeepSkyBlue" />
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>

                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="Border" Property="Background"
                                Value="DeepSkyBlue" />
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>

                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Border" Property="Background"
                                Value="DeepSkyBlue" />
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

<!-- Window - doesn't work -->
    <Style TargetType="{x:Type Window}">
        <Setter Property="Background">
            <Setter.Value>
                <ImageBrush ImageSource="images/groceryLog.jpg"/>
            </Setter.Value>
        </Setter>
    </Style>

如果映像构建操作设置为 "Content",此路径将有效。

如果设置为"Resource",则需要不同的路径:

<ImageBrush ImageSource="pack://application:,,,/images/groceryLog.jpg" />