views:

550

answers:

3

I'm trying to get a screen in silverlight where the user can enter their own text and add line breaks as neccesary. The problem is that whenever they hit return inside of a text block, nothing happens. Is there some way around this?

Thanks

+1  A: 

Nevermind, I figured out you needed to set the AcceptsReturn property to true.

Correl
A: 

[Edit: For whoever voted my answer down -- the question was "how do you capture enter in a text block". The text block element does not have an AcceptsReturn attribute.]

You should be able to trap for the Enter key and insert a newline character.

    private string textBuffer = "";
    private void TextBlock_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            textBuffer += Environment.NewLine;
        }
        else
        {
            textBuffer += e.Key.ToString();
        }
        Text.Text = textBuffer;
        e.Handled = true;
    }
Timothy Lee Russell
A: 

About the answer from another Timothy, TextBlock is not for typing. Are you sure you really don't want to use a TextBox instead?