我想实现一个用户可以选择两种字体的功能。 一种字体用于英文,另一种用于中文字符。 它类似于Microsoft Word中的字体设置,就像下面的链接一样。 http://blogs.igalia.com/jaragunde/files/2014/04/Word-font-selector.png
我知道wpf中有一些叫做复合字体的东西。但是我需要让用户实时更改这两种语言的字体,就像微软一样。 我该如何实现它? 谢谢!
答案 0 :(得分:0)
您可以使用RichTextBox控件。请参阅以下代码。
<StackPanel>
<RichTextBox Width="100" Height="200" x:Name="txtRich"/>
<Button Content="Set Arial Font" Click="Button_Click"/>
<Button Content="Set Tahoma Font" Click="Button_Click_1"/>
</StackPanel>
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!txtRich.Selection.IsEmpty)
{
TextRange selectionTextRange = new TextRange(txtRich.Selection.Start, txtRich.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily("Arial"));
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (!txtRich.Selection.IsEmpty)
{
TextRange selectionTextRange = new TextRange(txtRich.Selection.Start, txtRich.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily("Tahoma"));
}
}