如何立即获取文本块的所需宽度? [英] How to get the textblock's desiredwidth right now?
本文介绍了如何立即获取文本块的所需宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个空的TextBlock,我在cs代码中设置了Text,然后我调用了textblock的updatelayout方法,以获得
I have a null TextBlock, and I set the Text in cs code, then I have call the textblock's updatelayout method, in order to get the
DesiredSize.Width,但我失败了。
DesiredSize.Width, but I failed.
那么在现在设置文本后如何获得DesiredSize?
So how can I get the DesiredSize after set the Text right now?
推荐答案
Hi Shirley,
Hi Shirley,
我现在还不知道null-TextBlock应该是什么,但在访问DesiredSize之前调用测量将是最佳选择。
I don't now exactly what a null-TextBlock should be, but calling Measure before accessing DesiredSize would be the way to go.
TextBlock txt = new TextBlock();
txt.Text = "Hello";
txt.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
double width = txt.DesiredSize.Width;
这篇关于如何立即获取文本块的所需宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文