【问题标题】:how load files, icons, xaml files embedded in the project?如何加载项目中嵌入的文件、图标、xaml 文件?
【发布时间】:2023-01-18 22:18:10
【问题描述】:

在属性中将文件设置为“嵌入式资源”就像一个字符一样工作并且很简单 pload,如下所示:

var assembly = Assembly.GetExecutingAssembly();
        string resourceName = assembly.GetManifestResourceNames()
            .Single(str => str.EndsWith("svgImage.xaml"));

        using (Stream stream = assembly.GetManifestResourceStream(resourceName))
        using (StreamReader reader = new StreamReader(stream))
        {
            string result = reader.ReadToEnd();
        }

但是,如果我从“嵌入式资源”更改为仅资源....它不再起作用,我想加载一个我转换为 xaml 文件的 svg 图像,以插入在代码中动态创建的网格的资源字典中

有小费吗?

【问题讨论】:

  • svgImage.xaml 的内容是什么?为什么它有 xaml estension 当你说它是 svg

标签: c# wpf xaml svg embedded


【解决方案1】:

您可以简单地在项目中创建一个名为资源并将文件添加为资源.
像这样加载内容:

File.ReadAllText("pack://application:,,,/YourProjectName;component/Resources/svgImage.xaml")

当然你需要替换项​​目名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    相关资源
    最近更新 更多