title: TextWrapping inside a DataGrid
body: <h1>Goal</h1>
  <p>I have a WPF application that contain text inside a <code>DataGrid</code>.
  I want the text to wrap inside each cell.
  I also want to set a MinWidth for each column and if it has to, the <code>ScrollViewer</code> should create the horizonatl scroll bar.
  I never want a horizontal scroll bar to appear for the any of the cells or the <code>DataGrid</code> itself.
  If the user resizes the window, the rows should grow or shrink to accommodate the text wrapping, but it shouldn't allow the coulmns get so thin that they are no longer readable.</p>
  <h1>Problem</h1>
  <p>Right now, the text doesn't wrap because it is in a scrollviewer.
  I know of different ways that I can change this sample to get the text to wrap, but I can't get it to act exactly how I want it, as mentioned above.</p>
  <h1>Simplified xaml</h1>
  <pre><code>&lt;Window x:Class=&quot;SampleApp.MainWindow&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:local=&quot;clr-namespace:SampleApp&quot;
      Title=&quot;App&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
  
      &lt;Window.Resources&gt;
          &lt;Style x:Key=&quot;WrappingTextBlock&quot; TargetType=&quot;TextBlock&quot;&gt;
              &lt;Setter Property=&quot;TextWrapping&quot; Value=&quot;Wrap&quot;/&gt;
          &lt;/Style&gt;
          &lt;Style x:Key=&quot;WrappingTextBox&quot; TargetType=&quot;TextBox&quot;&gt;
              &lt;Setter Property=&quot;TextWrapping&quot; Value=&quot;Wrap&quot;/&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width=&quot;Auto&quot;/&gt;
              &lt;ColumnDefinition Width=&quot;*&quot;/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height=&quot;Auto&quot;/&gt;
              &lt;RowDefinition Height=&quot;*&quot;/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;Stuff ... /&gt;
  
          &lt;MoreStuff ... /&gt;
  
          &lt;Border Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot;&gt;
              &lt;ScrollViewer&gt;
                  &lt;StackPanel&gt;    
                      &lt;DataGrid HorizontalAlignment=&quot;Left&quot; ItemsSource=&quot;{Binding AwesomeObject, Mode=TwoWay}&quot; Margin=&quot;5&quot; AutoGenerateColumns=&quot;False&quot;&gt;
                          &lt;DataGrid.Columns&gt;
                              &lt;DataGridTextColumn Header=&quot;#&quot; Binding=&quot;{Binding Number, Mode=TwoWay}&quot;/&gt;
                              &lt;DataGridTextColumn Header=&quot;Header&quot; Binding=&quot;{Binding Data, Mode=TwoWay}&quot;/&gt;
                              &lt;DataGridTextColumn MinWidth=&quot;50&quot; Header=&quot;Long Text&quot; Binding=&quot;{Binding SoMuchText, Mode=TwoWay}&quot; ElementStyle=&quot;{StaticResource WrappingTextBlock}&quot; EditingElementStyle=&quot;{StaticResource WrappingTextBox}&quot;/&gt;
                          &lt;/DataGrid.Columns&gt;
                      &lt;/DataGrid&gt;
                  &lt;/StackPanel&gt;
              &lt;/ScrollViewer&gt;
          &lt;/Border&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>