我们要求为特定外语使用特定字体。基于这个问题的答案,似乎CompositeFont将是处理这个问题的最好方法。
Best way to localize fonts in wpf
但我正在努力让该死的东西发挥作用。
我已经创建了一个Font.CompositeFont文件,如下所示
<FontFamily xmlns="http://schemas.microsoft.com/winfx/2006/xaml/composite-font"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Baseline="0.9"
LineSpacing="1.2">
<!-- Name mapping -->
<FontFamily.FamilyNames>
<System:String Key="en-US">MyFont</System:String>
</FontFamily.FamilyNames>
<!-- Faces to report in font chooser UI -->
<FontFamily.FamilyTypefaces>
<FamilyTypeface Weight="Normal"
Stretch="Normal"
Style="Normal"
UnderlinePosition="-0.1"
UnderlineThickness="0.05"
StrikethroughPosition="0.3"
StrikethroughThickness="0.05"
CapsHeight="0.5"
XHeight="0.3" />
<FamilyTypeface Weight="Bold"
Stretch="Normal"
Style="Normal"
UnderlinePosition="-0.1"
UnderlineThickness="0.05"
StrikethroughPosition="0.3"
StrikethroughThickness="0.05"
CapsHeight="0.5"
XHeight="0.3" />
</FontFamily.FamilyTypefaces>
<FontFamily.FamilyMaps>
<FontFamilyMap Unicode="0000-052F, 1D00-1FFF, FB00-FB0F"
Target="Comic Sans MS"
Scale="1.0" />
</FontFamily.FamilyMaps>
</FontFamily>
build属性已设置为Resource,并且已使用.CompositeFont文件名保存。
但是,将我的任何字体的FontFamily设置为“/#MyFont”似乎不会设置字体。我确定在某个地方我已经错过了一个步骤,但如果我能找到有关该步骤的任何资源,我会被诅咒。 (不过我会继续寻找)
按照以下方式设置字体
<Style x:Key="defaultLabelFont"
TargetType="Label">
<Setter Property="FontFamily"
Value="#MyFont" />
<Setter Property="FontSize"
Value="12" />
<Setter Property="VerticalAlignment"
Value="Bottom" />
<Setter Property="HorizontalAlignment"
Value="Center" />
</Style>
如果有人能指出我正确的方向,我会非常感激。
答案 0 :(得分:0)
我建议处理InputLanguageChanged
事件
System.Windows.Input.InputLanguageManager.Current.InputLanguageChanged +=
Current_InputLanguageChanged;
并决定字体系列或大小等。
private void Current_InputLanguageChanged(object sender, InputLanguageEventArgs e)
{
if (e.NewLanguage.EnglishName == "...")
Application.Current.MainWindow.FontFamily = new FontFamily("Times New Roman");
else
{
// ...
}
}