Avatar of Angela4eva
Angela4eva

asked on 

wpf textbox limit text

I have text box in wpf xaml and I want the user to not be able to enter more than 60 characters.. when the starts typing it should tell tem how many charcters they have left to type when they copy paste let them not paste it. I am new to wpf any help appreciated
Programming Languages-OtherProgrammingASP.NET

Avatar of undefined
Last Comment
Angela4eva
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

Set the MaxLength property of the textbox to 60.

Add a label after the textbox and create an event for the textbox.TextChanged event set the Label.Text to be textbox.MaxLength - textbox.Text.Length + " Characters remaining"

With the MaxLength property set I wouldn't worry about being able to paste it will still only allow 60 chars

Regards
Gav
ASKER CERTIFIED SOLUTION
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Angela4eva
Angela4eva

ASKER

great solution. thank you
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo