2
votes

I have some text in a ScrollViewer control written in c# code, how do I wrap the text? Any solution?

Initialy I have a pop-up, inside this a stack panel and added

ScrollViewer sv = new ScrollViewer();

In this scroll viewer i put some text.

string values[]= new string[]; //(example)
sv.Content = values[1];

When I open pop-up, if text length is more than screen size, he need to show scroll bar.

 sv.TextWrapping = TextWrapping.Wrap; 

is possible or something another way? All items ( scroll viewer, text ) I puts behind view, not in xaml (view) because my content are dynamic.

2

2 Answers

1
votes

Create a TextBlock, assign the text to this TextBlock and add this TextBlock as the content of the ScrollViewer

var sv = new ScrollViewer();
var tb = new TextBlock
{
    Text  = //your text,
    TextWrapping = TextWrapping.Wrap
}
sv.Content = tb;
1
votes

For you to be able to scroll anything inside a scrollviewer, you have to stop the scrollviewer from growing with the child element.

If this happens dynamically, give the scrollviewer a certain height and the text inside it will be scrollable