开发者

Get line count from Silverlight RichTextBox?

Does anyone of a way to get a line count from开发者_JS百科 a Silverlight RichTextBox? I've tried counting the <Run> tags but that doesn't seem to be very accurate. The text in the RichTextBox will be different each time, so I need a good solid way to calculate how many lines of text are when the user is finished typing.

Does anyone know of a way to do this?


Well I had this code involving the run tags too (I didn't write it and I can't remember where it was taken from so I won't take any credit for it). Is it different from yours?

int blockCount = 0; 
int lineCount = 0; 
foreach (Block b in myRTB.Blocks) 
{ 
    if (b is Paragraph) 
    { 
        p = new Paragraph(); 
        p = b as Paragraph; 
        foreach (Run run in p.Inlines) 
        { 
            lineCount++; 
        } 
        blockCount++; 
    } 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜