I'm new to WPF Interoperability in VB.net Window Forms.
I'm making a Windows Form Application where I'm trying to add custom usercontrols with ElementHost that uses a custom font family.
I've created a custom button with a label inside it, where I have applied a custom font 'Raleway' from Google Fonts that I've loaded into Resources.
<UserControl x:Class="ButtonDark"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:prjButtonTestFont"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="150">
<Button Content="Button" BorderBrush="{x:Null}" Foreground="{x:Null}" >
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border" Background="#ff332d2f" CornerRadius="4" BorderBrush="#ff4e4749" BorderThickness="4">
<Label x:Name="Labelx" Content="Click" FontFamily="/prjButtonTestFont;component/Resources/#Raleway Thin" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#ff4e4749" FontSize="24" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="green"/>
<Setter TargetName="Labelx" Property="Foreground" Value="green"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="white"/>
<Setter TargetName="Labelx" Property="Foreground" Value="white"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
Image of xaml design preview showing the font corretly enter image description here
Image of Windows Form with the usercontrol button showing the incorrect font enter image description here
The problem is that the font wont display when I run the application, but it will display correctly in the xaml design preview window.
I've tried all the following file paths to the font, which all show the correct font in the xaml design preview window, but do not when I run the application.
FontFamily="./#Raleway Thin"
FontFamily="/prjButtonTestFont;component/Resources/#Raleway Thin"
FontFamily="../Resources/#Raleway Thin"
FontFamily="../#Raleway Thin"
FontFamily="Raleway-Thin.ttf/#Raleway Thin"
FontFamily="../Resources/Raleway-Thin.ttf/#Raleway Thin"
FontFamily="/prjButtonTestFont;component/Resources/Raleway-Thin.tff/#Raleway Thin"
FontFamily="/Resources/Raleway-Thin.ttf#Raleway Thin"
FontFamily="Raleway-Thin.ttf#Raleway Thin"
FontFamily="Raleway-Thin.TTF#Raleway Thin"
FontFamily="/Resources/Raleway-Thin.TTF#Raleway Thin"
I've also tried applying FontFamily to and with the same results!
I am looking for any solution whether programmatically in vb code or through xaml. I just need the font to show up once the application is launched.