Typography不包含0个参数的构造函数
时间: 2023-12-08 17:03:18 浏览: 31
是的,您说得对。Typography类没有包含0个参数的构造函数。Typography类的构造函数需要至少一个参数,即上下文参数,用于获取当前应用程序的主题和资源。例如,您可以使用以下代码创建一个Typography对象:
```
Typography typography = new Typography(getContext());
```
相关问题
Typography是个抽象接口不能实例化,且没有0个参数的构造函数实现
非常抱歉,我的回答还是有误。在.NET 6中,确实没有Typography类。您可以在TextRunProperties类中使用TypographyVariants属性来设置字符间距和其他排版属性。以下是一个示例:
```csharp
FormattedText formattedText = new FormattedText(
"Hello, world!",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface("Arial"),
12,
Brushes.Black,
new TextFormatter(new TextParagraphProperties(), new TextRunProperties() { Typography = new Typography() { Variants = new FontVariants() { Superscript = true } } }));
formattedText.SetFontSize(18);
formattedText.SetForegroundBrush(Brushes.Red);
// 设置字符间距
formattedText.SetTypographyVariants(new FontVariants() { CharacterSpacing = 2 });
// 绘制 formattedText 对象
```
请注意,我们使用了TextRunProperties类的TypographyVariants属性来设置字符间距和其他排版属性。TypographyVariants属性的类型是FontVariants,它表示字符间距和其他字体变体。在上面的示例中,我们使用了SetTypographyVariants方法来设置字符间距。
Typography.SetKerning如何Binding到KerningToSpacingConverter
`Typography.SetKerning`是一个WPF控件的附加属性,用于指定文本的字符间距。而`KerningToSpacingConverter`是一个WPF值转换器,用于将字符间距转换为单词间距。如果要将`Typography.SetKerning`绑定到`KerningToSpacingConverter`,可以使用以下步骤:
1. 在XAML中定义需要使用`Typography.SetKerning`的控件,并将该属性绑定到ViewModel中的一个属性,例如:
```xaml
<TextBlock Text="{Binding Text}"
TextOptions.TextFormattingMode="Display"
TextOptions.TextHintingMode="Animated"
Typography.SetKerning="{Binding KerningEnabled}" />
```
这里我们将`Typography.SetKerning`绑定到ViewModel中的`KerningEnabled`属性。
2. 在同一个XAML文件中,定义一个`KerningToSpacingConverter`,例如:
```xaml
<local:KerningToSpacingConverter x:Key="KerningToSpacingConverter" />
```
其中,`local`是你定义这个转换器的命名空间。
3. 在控件中使用`KerningToSpacingConverter`,将`Typography.SetKerning`的值转换为单词间距。例如:
```xaml
<TextBlock Text="{Binding Text}"
TextOptions.TextFormattingMode="Display"
TextOptions.TextHintingMode="Animated"
Typography.SetKerning="{Binding KerningEnabled}"
LineStackingStrategy="BlockLineHeight"
LineHeight="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Converter={StaticResource KerningToSpacingConverter}, ConverterParameter=1.1}" />
```
在这个例子中,我们使用`KerningToSpacingConverter`将`Typography.SetKerning`的值转换为单词间距,并将该间距赋值给`LineHeight`属性。注意,这里的`ConverterParameter`参数是一个倍数,用于调整单词间距的大小。
绑定`Typography.SetKerning`到`KerningToSpacingConverter`的过程就是这样。通过这种方式,我们可以在控件中动态地调整字符间距和单词间距,从而达到更好的文本排版效果。