使 TextBlock 文本逐字符显示
我正在尝试设置 TextBlock
的样式,使其看起来像每次更新其内容时,内容都会更新,就像我们逐个字符地输入内容一样。有人能让我朝着正确的方向开始吗?我不知道该怎么办。
I'm trying to style a TextBlock
to make it look like everytime I update its content, the content updates like we were typing it in, character by character. Can someone start me off in the right direction? I have no clue what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议创建一个行为(有很多关于创建这些行为的示例)。就您而言,您可以创建一个行为。
由于 TextBlock 不公开 TextChanged 事件,因此您可能必须挂钩 Text 属性的绑定,然后运行代码。您可以将文本清除为空字符串,然后一一延迟添加字符(注意:在更新文本时,您需要停止侦听文本的更改)。
I'd suggest creating a Behavior (there are lots of examples out there on creating these). In your case, you could just create a Behavior.
Since the TextBlock doesn't expose a TextChanged event, you'd probably have to hook into the binding for the Text property and then run your code. You could clear the text to an empty string and then add the characters one by one with a delay (note: you'd need to quit listening for changes to Text while you're updating it).