问题描述
如何在 xaml 的 TextBlock 中设置允许用户输入的字符数?
How would I set the number of characters a user is allowed to input in a TextBlock in xaml?
我是在模型上做还是创建某种自定义属性来处理它?
Would I do it on the Model or create some sort of custom attribute to handle it?
推荐答案
TextBlock 没有 MaxLength,Label 也没有.文本框可以.除非您修改了 TextBlock,否则用户无法输入它.
TextBlock doesn't have a MaxLength, neither does Label. TextBox does. Users cannot input into a TextBlock unless you have modified it.
它真的是您想要限制的 TextBlock 还是您的意思是 TextBox?如果它是一个 TextBox,你可以简单地使用 MaxLength 属性.
Is it really a TextBlock you want to limit or did you mean a TextBox? If it is a TextBox you can simply use the MaxLength property.
<TextBox Name="textBox1" MaxLength="5" />
如果它确实是您正在使用的 TextBlock 并且以某种方式允许用户向其中输入数据,则切换到使用 TextBox.如果它是您所追求的 TextBlock 样式,您可以将 TextBox 设置为看起来像一个 TextBlock.
If it really is a TextBlock you are using and somehow allowing a user to input data into it, then switch to use a TextBox. If it is the TextBlock style you are after, you can style the TextBox to look like a TextBlock.
这篇关于在 XAML 中设置 TextBlock 的最大字符长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!