Imge 到窗口样式背景未加载 wpf



我是WPF的新手,在阅读了一些关于将图像放入窗口背景的文章后,我仍然无法使其工作。有人可以告诉我我做错了什么吗?我的杂货日志.jpg设置为资源,并在复制到输出时设置了"如果较新则复制"。我的应用.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>

如果映像生成操作设置为"内容",则此路径将起作用。

如果设置为"资源",则需要其他路径:

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

相关内容

  • 没有找到相关文章

最新更新