0

I want the user be able to insert a biography in 6 lines or less. The problem is that TextBox in windows phone doesn't have a MaxLines property or LineCount, even newline character isn't available. So how can I solve this problem? thanks.

user3293835
  • 829
  • 2
  • 15
  • 30
  • 1
    The total number of characters might be a better way to limit this as your design would mean depending on the screen size or orientation that the user may be able enter more/less total text than someone else. Consider: Just trim it later when it's shown to 6 lines and have a "more" button to see the full text. – WiredPrairie Mar 08 '14 at 13:54
  • I think you can try with this solution: http://stackoverflow.com/questions/4791062/how-to-represent-line-break-or-new-line-in-silverlight-textbox for line breaks. But i think you should write your own validation function that will be fired for every character written by user. When he exceed your max character limit, trim text to max character limit and so on... – Jacob Sobus Mar 10 '14 at 12:19

2 Answers2

0

I am not a windows phone programmer but based on my experience with c#.Net, I guess we can build a logic that would do the thing:

try this:

string txtData = this.txtTextBox.Text;

        string[] splitByCRet = txtData.Split(new string[]{"\r\n"},  StringSplitOptions.None );

        if (splitByCRet.Length > 6)
        {
            //Exceeds the limit;

            MessageBox.Show("Exceeds");
        }
        else
        {
            MessageBox.Show("Ok to proceed");
        }
pareto
  • 196
  • 5
  • each character can has a different width so each line doesn't have a fixed number of characters – user3293835 Mar 08 '14 at 09:36
  • I don't think this is what he is looking for (To im its a matter of styling), he is not looking in fact to : "Environment.NewLine", cause you can have a long sentence (text) that goes on 3 lines, while as long as you didn't hit "Enter" it wont consider it a different line (wont add the "\r\n"), so you can have txtData written on 10 lines, but still doesn't contain any : "\r\n". – KADEM Mohammed Mar 08 '14 at 09:39
  • Then perhaps you'd need to specify a fixed width and height for the textbox. You can apply further logic like specify the number of characters in the box – pareto Mar 08 '14 at 09:44
0

I'm not sure it's what are you looking for but try:

yourTextBox.Height = yourTextBox.LineHeight * 6;

and of course set TextWrapping of your textbox.

Mateusz Rogulski
  • 7,357
  • 7
  • 44
  • 62
  • yes, but it will not prevent user from inserting more texts, which means first line will disappear from top and user can continue typing. – user3293835 Mar 10 '14 at 12:19