我有我试图改变利用由一些遗留码供给的System.Drawing.Font对象的外观的WPF标签控制。我已经能够设定大多数的属性,但我有删除线和下划线挣扎。

到目前为止,我有:

System.Drawing.Font font = FontFromLegacyCode();

System.Windows.Controls.Label label = new System.Windows.Controls.Label();
label.FontFamily = new System.Windows.Media.FontFamily( font.Name );
label.FontWeight = font.Bold ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Regular;
label.FontStyle = font.Italic ? System.Windows.FontStyles.Italic : System.Windows.FontStyles.Normal;
label.FontSize = font.Size;

您如何设置字体删除线或下划线属性?有没有更好的控制使用?

有帮助吗?

解决方案

我将其更改为一个TextBlock控制。该TextBlock控件具有可以使用TextDecorations属性。

<TextBlock Name="textBlock" TextDecorations="Underline, Strikethrough" />

或者你可以坚持一个标签内的TextBlock如果你真的喜欢(虽然我只是本身使用TextBlock的)。

<Label Name="label">
    <TextBlock Name="textBlock" TextDecorations="Underline, Strikethrough" />
</Label>

有一个在所述 TextDecorations 类。

我发现的TextBlocks比在大多数情况下标签更合适。以下是关于差异博客帖子。的主要不同之处在于一个标签是一种控制,而一个TextBlock只是一个FrameworkElement的。还一个标签支持访问键。

其他提示

看着你已有的代码,可能有问题的。 在MSDN上 Windows窗体和WPF属性映射他们所做的评论:

  

在WPF字体大小被表示为一英寸的九十六分之一,和Windows形式英寸七十二分之一。相应的转化率是:

     

Windows窗体字体大小= WPF字体大小* 72.0 / 96.0。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top