1

On a windows store app project, i have 2 StackPanels one with 200x200 and another with 200x500 and a scrollviewer inside it(just the second one), i also have a string with some text.

what i want is to split the string so that i get 2 strings, and the first one fits on the 200x200 area, and the rest will go to the second stackapanel with the scrollviewer.

How can i split a string according to the dimensions?

i tried using some functions like this one but dindt quite get it.

private void textBox1_TextChanged(object sender, EventArgs e)
    {
        Size size = TextRenderer.MeasureText(textBox1.Text, textBox1.Font);
        textBox1.Width = size.Width;
        textBox1.Height = size.Height;
    }
Thought
  • 5,326
  • 7
  • 33
  • 69

1 Answers1

1

What you need is FormattedText class. TextRenderer is for WinForms, not WPF.

You can find sample implementation here: WPF equivalent to TextRenderer. You may need to asjust code to apply width and height of the box.

There're also methods for WinRT: How can I calculate the width of a string in Metro (without displaying it)?, but they depend on creating a TextBlock which isn't rendered.

Community
  • 1
  • 1
Athari
  • 33,702
  • 16
  • 105
  • 146