【问题标题】:Images from resource don't appear来自资源的图像不出现
【发布时间】:2012-03-06 15:48:21
【问题描述】:

我尝试将图像加载到我的 WPF 项目的主窗口中。首先,我创建了名为 Images.resx 的 RESX 文件(它位于 Properties 文件夹中)。然后我在这个资源中添加了一个名为 logo.png 的图像(使用 VS2010 RESX 编辑器)。图像已正确复制到资源文件夹中。然后我将 Build Action 属性从 Embedded Resource 更改为 Resource。在此之后,我想在 XAML 中加载我的图像。

<Image x:Name="image" Source="/MyProject;component/Resources/Logo.png" />

在 Expression Blend 的预览中出现了一张图片,但是当我编译程序时,有一个空窗口(没有图片)。

接下来我使用了 ResourceDictionary。我创建了新文件 - Theme.xaml 并添加了这个:

<BitmapImage x:Key="logo" UriSource="/MyProject;component/Resources/Logo.png" />

在 MainWindow.xaml 中:

    <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles/Theme.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<Image x:Name="image" Source="{StaticResource logo}" />

在 Expression Blend 中再次正常,但编译后...什么也没有出现:/

我尝试将 Build Action 改回 Embedded Resource。什么都没发生。

谁能告诉我如何在 XAML 中使用来自 RESX 文件的嵌入式资源? 提前致谢。

【问题讨论】:

标签: wpf image xaml resources resx


【解决方案1】:

好的。我找到了答案...当我将一些图像添加到我的 RESX 文件中时,它会出现在 Resource 文件夹中。现在我必须在资源文件夹中更改我的 RESX 文件和图像的构建操作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    相关资源
    最近更新 更多