You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Power Apps中用集合内文件作为图片与视频控件源?

Power Apps 本地文件路径加载与画廊跳转解决方案

核心需求:加载图片/视频路径

1. Image 控件加载图片路径

Power Apps 不识别 .\folder\pic.png 这类相对路径,需将路径转换为可读取的本地文件格式:

  • 若所有文件存储在固定根目录(如 C:\MyAppAssets\),在 Image 控件的 Image 属性中输入:
File.ReadBinary(
    Substitute(
        Substitute(ThisItem.'File [File]', ".\", "C:\MyAppAssets\"),
        "\", "/"
    )
)
  • 若路径相对于 Excel 文件所在位置,可通过 Host.FilePath() 获取 Excel 路径并拼接:
File.ReadBinary(
    Uri.PathCombine(
        Left(Host.FilePath(), Find("\", Host.FilePath(), Len(Host.FilePath()) - Len(Dir(Host.FilePath())) + 1)),
        Substitute(ThisItem.'File [File]', ".\", "")
    )
)

2. Video 控件加载视频路径

Video 控件支持本地文件 URI,需将相对路径转换为 file:/// 开头的标准格式,在 Video 控件的 Media 属性中输入:

"file:///" & Substitute(
    Substitute(ThisItem.'File [File]', ".\", "C:\MyAppAssets\"),
    "\", "/"
)

注意:确保视频格式为 Power Apps 支持的类型(如 MP4、MOV),且已在应用设置中开启本地文件访问权限。

延伸需求:画廊显示+跳转详情页

1. 画廊设置

  • 画廊数据源绑定你的目标集合
  • 画廊内的 Image 控件,根据文件类型显示对应内容:
If(
    // 判断图片格式
    EndsWith(Lower(ThisItem.'File [File]'), ".png") || EndsWith(Lower(ThisItem.'File [File]'), ".jpg") || EndsWith(Lower(ThisItem.'File [File]'), ".jpeg"),
    // 加载图片
    File.ReadBinary(Substitute(Substitute(ThisItem.'File [File]', ".\", "C:\MyAppAssets\"), "\", "/")),
    // 视频显示缩略图,可替换为自定义图标
    Video.Thumbnail(Substitute(Substitute(ThisItem.'File [File]', ".\", "C:\MyAppAssets\"), "\", "/"))
)
  • 画廊 OnSelect 属性设置跳转并传递选中项:
Navigate(DetailScreen, None, {SelectedFile: ThisItem})

2. 详情页设置

  • 新建 DetailScreen,添加 Image 和 Video 控件:
    • Image 控件:
      • Visible 属性:EndsWith(Lower(SelectedFile.'File [File]'), ".png") || EndsWith(Lower(SelectedFile.'File [File]'), ".jpg") || EndsWith(Lower(SelectedFile.'File [File]'), ".jpeg")
      • Image 属性:复用核心需求中 Image 控件的公式
    • Video 控件:
      • Visible 属性:EndsWith(Lower(SelectedFile.'File [File]'), ".mp4") || EndsWith(Lower(SelectedFile.'File [File]'), ".mov")
      • Media 属性:复用核心需求中 Video 控件的公式

内容的提问来源于stack exchange,提问作者Bryan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 22:55:30