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

PowerShell中用XamlReader加载含FontAwesome IconImage的XAML报错

在PowerShell中通过XamlReader加载含FontAwesome IconImage的XAML时出错

我将Visual Studio 2022中创建的简单WPF项目XAML文件移植出来,目的是在PowerShell脚本中通过[Windows.Markup.XamlReader]::Load方法实例化窗口。窗口本身可正常加载,且已为元素添加x:Name引用并在脚本中映射了事件处理程序。

但在XAML中为按钮添加IconImage时,触发以下错误:

Unable to load Windows.Markup.XamlReader: Exception calling "Load" with "1" argument(s): "Cannot create unknown type '{https://schemas.awesome.incremented/wpf/xaml/fontawesome.sharp}IconImage'.".Exception.Message

XAML中已添加FontAwesome的命名空间引用:

xmlns:fa="https://schemas.awesome.incremented/wpf/xaml/fontawesome.sharp"

我把XAML和脚本放在同一文件夹,用VS Code打开时,输入<fa:IconImage Icon="Home" Foreground="White"/>能被智能感知识别,但执行PowerShell脚本时仍报错。

回到原WPF项目的XAML副本,添加图标后编译运行完全正常,说明FontAwesome本身没有问题。推测是PowerShell用XamlReader加载XAML时,缺失了NuGet为WPF项目安装的特定依赖/引用——原项目仅在PackageReference列表中能看到FontAwesome.Sharp,代码文件里没有显式引用。

已尝试以下方案但均无效:

  • 将xmlns改为程序集引用,智能感知能识别更多关键词,但加载错误依旧
  • 尝试通过资源字典直接访问字体,需要用TextBlock形式添加,但Button仅允许一个内容引用
  • 用Run标签拼接文本块,结果只显示方块,无法识别从FA CheatSheet复制的转义序列

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 06:42:29