【发布时间】:2017-06-26 12:19:30
【问题描述】:
我不熟悉 VB.net 窗口窗体中的 WPF 互操作性。
我正在制作一个 Windows 窗体应用程序,我正在尝试使用使用自定义字体系列的 ElementHost 添加自定义用户控件。
我创建了一个内部带有标签的自定义按钮,我在其中应用了来自 Google 字体的自定义字体“Raleway”,该字体已加载到资源中。
<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>
正确显示字体的 xaml 设计预览图 enter image description here
用户控件按钮显示错误字体的 Windows 窗体图像 enter image description here
问题是我运行应用程序时字体不显示,但在xaml设计预览窗口中会正确显示。
我已经尝试了字体的以下所有文件路径,它们都在 xaml 设计预览窗口中显示了正确的字体,但在我运行应用程序时却没有。
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"
我也尝试过将 FontFamily 应用到相同的结果!
我正在寻找任何解决方案,无论是在 vb 代码中还是通过 xaml 编程。我只需要在应用程序启动后显示字体。
【问题讨论】:
标签: wpf vb.net winforms xaml visual-studio-2015