Cannot create a FontAwesome.Sharp IconImage instance for a WPF window instantiated from XamlReader::Load in PowerShell

16 views Asked by At

I ported a XAML file that I created from a simple WPF project in Visual Studio 2022 with the purpose of instantiating it from a PowerShell script using the [Windows.Markup.XamlReader]::Load method. The window itself can be loaded and I've already added a few x:Name references and mapped some event handlers in my PowerShell script to the window elements.

My problem came about when I tried to add an IconImage to a button in my XAML code. I get the following error:

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

As those familiar with using FontAwesome in WPF projects probably already know, the xmlns reference is as follows:

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

I have the XAML file and my script in a folder, which I opened in Visual Studio Code. What's odd is that as I was entering the following element in my XAML code, intellisense actually knew that 'IconImage' is a valid object name to follow the 'fa' namespace reference, yet, I get the above error.

<fa:IconImage Icon="Home" Foreground="White"/>

When I went back to the copy of the XAML code from my WPF project, I'm able to add the Icon there and see it in the compiled window, so it's not an issue with FontAwesome itself. Is there a specific dependency/reference installed by the nuget package manager to my WPF project that gets lost when trying to load the XAML file in PowerShell from the XamlReader Load method?

Other than its appearance in the "PackageReference" list for the WPF project, I don't see any specific references to the FontAwesome.Sharp assembly either in any of the project's .cs files.

I also tried creating the xmlns as an assembly reference. This actually makes a few more keywords visible to intellisense when trying to re-enter the tag, but again, I get the same error. Other options suggested (installing/creating a DictionaryResource to access the font directly) doesn't work, as it has to be entered as a TextBlock, which isn't allowed in a Button (can only have one content reference). I tried using the Run tag to concatenate two text blocks, but all I got was a Square, as in the code did not recognize the desired escape sequence that I copied directly from the FA CheatSheet page.

0

There are 0 answers