我有以下场景,我认为会有一个简单的解决方案,但我很困惑...
我构建了一个 WPF 用户控件,其中包含一组数字按钮和一个 TextBlock 来记录已选择的按钮。当用户控件打开时,TextBlock 为空。选择按钮后,其代表的数字将附加到所显示文本的右侧。
我需要的是一种解决方案,其中数字不断附加在右侧,如果这导致超出 TextBlock 的固定可显示大小,则会删除最左侧的字符。实际上,我追求的是一次一个角色的品牌效应。
我无法使用滚动条。任何想法都会受到欢迎
I have the following scenario which I thought would have a simple solution, but I'm stumped...
I have constructed a WPF user control with a set of numeric Buttons and a TextBlock to record what buttons have been selected. When the user control opens, the TextBlock is empty. As a button is selected, the digit it represents is appended to the right-hand-side of the displayed text.
What I need is a solution where the digits keep getting appended on the right-hand-side and if that results in exceeding the fixed displayable size of the TextBlock dropping the left-most character. In effect I am after a one-character-at-a-time marque effect.
I can not use scroll bars. Any thoughts would be welcome
发布评论
评论(2)
数据绑定是你的朋友。
假设你有一个 ViewModel。在 ViewModel 中,您获得了一个绑定到 TextBlock Text 属性的 string 属性。
现在,您只需使用常规 C# 字符串方法在 ViewModel 中操作该字符串即可正确显示。
HTH
阿里尔
Databindings are you friend here.
suppose you got a ViewModel. and in the ViewModel you got a property of string which is binded to the TextBlock Text propetry.
Now you only need to manipulate that string inside the ViewModel using regular c# string methods to display correctly.
HTH
Ariel
TextBlock 级别没有什么特别的...只需使用 string.SubString。
更新:这段代码应该可以解决问题:
There's nothing special at the TextBlock level... Just pass it the string that is formatted correctly using something like string.SubString.
UPDATE: This code should do the trick: