Visual Studio uses its own text editor control, not WPF's built in TextBox. Visual Studio's built-in text editor has many advanced features related to code editing but is not available separately from Visual Studio.
There are many open-source and componentware text editor controls available for WPF that include region collapsing. I suggest you download AvalonEdit or any of the text editor controls listed in this answer to see how it is done, and either reuse the control you downloaded or roll your own using similar techniques.
The technique most text editors use for region collapsing is to include a "outline hidden" flag in the data structure maintained for every line in addtion to an "is outline start" flag, an "outline end" pointer, and a "nesting level". By keeping these up to date and having the display templates honor them by drawing the proper icons/buttons and/or hiding the line, you can get the effect you need quite easily. Obviously this relies on your text editor's data structure tracking and displaying each line independently, which requires additional logic for selection, navigation, etc that is not included in WPF.