awesome-inc / FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
Apache License 2.0
376 stars 87 forks source link

Add support for showing Pro icons in Design Mode #121

Closed nj closed 1 month ago

nj commented 2 months ago

When including Pro fonts in a local project, it'll fail to load the fonts due to Assembly.GetEntryAssembly() being WpfSurface in Design Mode - hence won't load the proper project asssemply resources, neither for IconBlock nor IconImage: billede

It also triggers an Exception with Value cannot be null. (Parameter 'fontFamily') for IconBlock: billede

Above example with code in the TestWpf-project:

<StackPanel Grid.Row="9" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
    <faPro:IconBlock IconFont="Solid" Icon="WifiExclamation" fa:Awesome.Flip="Horizontal" FontSize="32" ToolTip="Flipped horizontally" Width="142" />
    <faPro:IconImage IconFont="Solid" Icon="WifiExclamation" fa:Awesome.Flip="Vertical" ToolTip="Flipped vertically" />
</StackPanel>

The %LocalAppData%\Microsoft\VisualStudio\<version reference>\Designer\Cache\<internal project build path> includes the fonts path (with the tff-files), in addition to the project assemply as well.

However, the next issue in this regards is, that even though a InitializeWpf function exists, this is within an internal class - and not available. In addition, doesn't seems to make much of a change even by trying to start early.

That said, there might be a more proper solution, to handle this particular scenario - just was without luck when trying...