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?
The IsReadOnly property of the TextBox sets the text box read only. By default, it is false. The MaxLength property of the TextBox sets the number of characters allowed to input in a text box.
TextBlock is not editable.
The WPF TextBlock control is a lightweight text editor control for displaying and formattting small amount of text flow content. The code examples in this tutorial demonstrates how to use a TextBlock control in WPF using XAML and C#. Creating a TextBlock. The TextBlock element represents a WPF TextBlock control in XAML ...
TextBlock doesn't have a MaxLength, neither does Label. TextBox does. Users cannot input into a TextBlock unless you have modified it.
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" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With