积极答复者
关于获取Textblock文本实际长度的问题

问题
答案
-
?????
- 已标记为答案 Franklin ChenMicrosoft employee 2015年1月22日 11:44
- 已编辑 Shi Xin 2015年7月27日 6:20
2015年1月20日 3:25
全部回复
-
你好,
对于TextBlock, 首先没有属性可以检测是否超出限定,你的需求很难被实现。
如果是RichTextBlock的话,它有HasOverflowContent属性,可以检测内容是否超出限制,不过现在的问题是不好判断每行的长度,假设每行16个数字,那如果超出了,就是16*MaxLines就可以了:
<RichTextBlock Grid.Row="0" Name="richTextBlock1" MaxLines="3" Width="100" TextWrapping="Wrap" > </RichTextBlock> <Button Grid.Row="1" Content="Click" Click="Button_Click" />
public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; richTextBlock1.Blocks.Clear(); var paragraph = new Paragraph(); paragraph.Inlines.Add(new Run { Text = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" }); richTextBlock1.Blocks.Add(paragraph); } private void Button_Click(object sender, RoutedEventArgs e) { if(richTextBlock1.HasOverflowContent==true) { Debug.WriteLine(16 * richTextBlock1.MaxLines); } else { richTextBlock1.SelectAll(); Debug.WriteLine(richTextBlock1.SelectedText.Length); } }
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.2015年1月8日 10:15 -
谢谢你的回答。
不过简单的使用每行的字数*行数结果可能不准确,毕竟每一行不一定都被填满了。
对于Textblock和RichTextBlock都不能实现这样的功能,我感到有点遗憾(实际上是恼火)
不过,只有想其他办法了。
你好,
目前确实有很多API没有公开,也有一些已知问题,如果有任何建议,可以去以下网站提交建议,报告问题,产品组会去收集:
https://wpdev.uservoice.com/forums/136284-dev-platform-%E4%B8%AD%E5%9B%BD
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.2015年1月11日 13:55 -
?????
- 已标记为答案 Franklin ChenMicrosoft employee 2015年1月22日 11:44
- 已编辑 Shi Xin 2015年7月27日 6:20
2015年1月20日 3:25