简体   繁体   English

TextBlock未正确对齐文本C#

[英]TextBlock not aligning text correctly C#

So I have a textblock that is receiving response text from a webclient 所以我有一个文本块,从webclient接收响应文本

When I do this call in a browser I get nicely formatted responses 当我在浏览器中执行此调用时,我得到了格式良好的响应

like this 像这样

在此输入图像描述

but when I do this in code and push it into my textblock I get this (note that all the data is there just scrolled off of the screenshot) 但是当我在代码中执行此操作并将其推入我的文本块时,我得到了这个(请注意,所有数据都只是从屏幕截图中滚动)

在此输入图像描述

Here is my textblock XAML 这是我的文本块XAML

 <TextBlock xml:space="preserve"  Text="{Binding toolResponseText,Mode=TwoWay}"/>

I was hoping the space preserve line would have fixed this but it didn't. 我希望太空保护线可以解决这个问题,但事实并非如此。

No, xml:space = preserve is talking about whitespace within the XAML. 不, xml:space = preserve正在讨论XAML中的空白。 It's not useful to you here. 这对你没用。

The important point is that the browser is displaying it with a monospaced font, whereas you're using a variable-width font. 重要的是,浏览器使用等宽字体显示它,而您使用的是可变宽度字体。

Try: 尝试:

FontFamily="Consolas"

within your XAML. 在你的XAML中。 (If that font family doesn't change the appearance, find another one which does, and is still monospaced...) (如果该字体系列没有改变外观,找到另一个,并且仍然是等宽的......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM