c# 如何获取资源文件夹中所有项目的文件路径

标签 c# wpf list file resources

我正在尝试使用这样的 BitmapImages 创建一个列表。

List<BitmapImage> Images = new List<BitmapImage>
{
    new BitmapImage(new Uri(@"/Images/Car.bmp", UriKind.Relative)),
};

现在我正在从资源\Images\中手动添加一张图片,但我不想对所有 68 张图片都这样做。 有没有办法制作一个方法,它将查看资源\Images\,并像上面那样输出所有 BitmapImage 路径的列表?

类似的东西。

Foreach(Item in Images)
{
    List.add(ItemPath + ItemName)
}

这是我正在谈论的文件夹的图片:

Image of folder structure

最佳答案

这里是如何通过模式获取文件

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images");
foreach (string file in Directory.GetFiles(path, "*.bmp"))
{
    // there is file name
}

关于c# 如何获取资源文件夹中所有项目的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49253629/

相关文章:

c# - dotNet 观察者,只观察 .dll 文件

c# - 错误 : No exports were found that match the constraint:

wpf - WPF 资源的范围 : Is pushing it to application scope (app. xaml) 对性能有好处吗?

java - 从 UnorderedListADT 生成 UnorderedVector,但出现未经检查的转换错误

python - 如何将 DataFrame 中的 K 个随机值附加到不重复的列表列表中?

c# - LINQ - 不同的语法风格,不同的结果?

c# - 我们可以在类中声明时初始化集合属性吗

Viewport3D 中的动画期间 WPF 闪烁

wpf - 如何将 DataGridTemplateColumn.Visibility 绑定(bind)到 DataGrid.ItemsSource 之外的属性?

python - 有效地从文件中读取主版本号