title: WPF DataGrid Hide RowDetails or Unselect Row
body: <p>I have a DataGrid who's RowDetails is set to show when selected (RowDetailsVisibilityMode="VisibleWhenSelected").  Now I want to be able to get rid of it!  I put a close button on the row details with this code:</p>
  
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
    {
     e.Handled = true;
     Button button = sender as Button;
     DataGridRow row = button.FindAncestor&lt;DataGridRow&gt;();
  
     row.DetailsVisibility = Visibility.Collapsed;
    }
  </code></pre>
  
  <p>That code gets me 90% there, but once the row details is collapsed for a given row it will not appear the next time that row is selected.</p>