I have a textbox with multi line, and textwrap set to Wrap. My requirement is to have a textbox that wraps exactly at 76th character of each line no matter what. To achieve this i have set width of the textbox to wrap exactly at 76 characters. But it kind of breaks when there is a whole word that is close to end of line and that word jumps to next line. I dont want that to happen. How do i fix it?
Asked
Active
Viewed 214 times
0
-
2That is how auto wrapping works, but if you want to do it exactly at 76 characters don't use textwarp but instead loop the string characters and put a new line every 76th character. – Dr. Stitch Feb 01 '16 at 02:29
-
If i do manually following scenarios has to be handled: 1. KeyDown-- also check for if the character is matching my conditions or not 2. some lines may have less than 76 characters so in that case its tough 3. Copy paste also have to be handled 4. I have MVVM not sure how this one will works – WPFKK Feb 01 '16 at 04:49
-
1@user841612 Put that logic in the code-behind of the view, it doesn't belong in the view model. – Mike Eason Feb 01 '16 at 08:13
-
1This do not to be a ViewModel concern though, sounds more like a pure view concern to me. `IValueConverter` may be the better option. Is the text two-way bound? – Tseng Feb 01 '16 at 08:16
-
Try using the TextChanged Event of the Textbox. It will trigger by manually input same as Copy/Paste. Inthere you can apply ur logic – Felix D. Feb 01 '16 at 11:20
-
Best way would be to create a behavior which you can attach to the TextBox --> reusability – fixagon Feb 01 '16 at 11:35
-
can someone post working logic? I tried but they did not work. Reason: TextBox.Lines property not available which is in ASP.Net. I tried preview keydown but unfortunately some lines have less than 76 characters and its not working. – WPFKK Feb 01 '16 at 12:34
-
show this: http://stackoverflow.com/questions/13733679/limit-the-max-number-of-chars-per-line-in-a-textbox – Mouaici_Med Apr 01 '16 at 11:06