WPF FlowDocument空间大小不一致
本文关键字:不一致 空间 FlowDocument WPF | 更新日期: 2023-09-27 18:12:29
我使用FlowDocumentScrollViewer
将日志输出打印到我的应用程序窗口,并且得到一些相当奇怪的间距问题。大多数空间的大小都是正确的,但在某些区域,我总是会得到太大的空间。下面是一个例子:
正确行距:"d copy E:'Projects"
显示内容:"d Copying E:'Projects"
我不得不使用多个空格来反映上面的间距问题,但我保证它确实只是显示一个大小不正确的空格。这很容易通过将我的FlowDocumentScrollViewer
中的文本复制到文本编辑器(如notepad++)中来验证。下面是我最简单的FlowDocumentScrollViewer
的打印代码:
LogBox.Document = new FlowDocument();
LogBox.Document.Background = LogBox.Background;
LogBox.Document.Foreground = LogBox.Foreground;
LogBox.Document.Blocks.Add(logParagraph = new Paragraph());
logParagraph.Margin = new Thickness(0); //Tested making Margin 0, didn't help
logParagraph.FontFamily = font;
logParagraph.FontSize = defaultFontSize;
...
public void PrintLog(String s)
{
logParagraph.Inlines.Add(s);
}
我从来没有见过这样的东西,在谷歌上搜索它是非常困难的,因为每个人使用"间距"作为关键字实际上是指行高…任何帮助都是感激的。
你试过吗?
LogBox.TextAlignment = TextAlignment.Left;
和/或
logParagraph.TextAlignment = TextAlignment.Left;
owo吗?因为正如我所看到的,在某些情况下,Block会自动对齐来对齐/拉伸行中的文本~不知道为什么,但似乎发生了;o
您可以尝试在PrintLog
方法中添加Run
对象,并修改其属性(如CharacterSpacing),也可以尝试其他属性。对不起,我现在不能访问Visual Studio,所以我不能实际尝试它。
public void PrintLog(String s)
{
var run = new Run();
// modify run properties here
logParagraph.Inlines.Add(run);
}
你可以在这里查看MS文档:运行Class