title: WPF: Easiest way to add control to grid based on ListView selection
body: <p>I have a <code>ListView</code> which contains items that should represent certain settings, which can be changed by the user. I am looking for the easiest way to link the <code>ListViewItem</code> to a custom user control.</p>
  
  <p>What I have now:</p>
  
  <pre><code>    &lt;ListView 
          Grid.Row="0" 
          Grid.Column="0"
          SelectionChanged="SettingsListViewSelectionChanged"&gt;
  
          &lt;ListViewItem x:Name="PathSettings" Content="Path"/&gt;
          &lt;ListViewItem x:Name="HideShowTvShows" Content="Hide/Show TV Shows"/&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p>And then in the code behind I figure out which item was clicked, and attach the corresponding <code>UserControl</code> to the <code>Grid</code>. </p>
  
  <pre><code>    private void SettingsListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          var listView = e.Source as ListView;
  
          if (listView != null)
          {
              SettingsContentPanel.Children.Clear();
  
              if (listView.SelectedItem.Equals(_pathSettings))
              {
                  SettingsContentPanel.Children.Add(_pathSettings);
  
                  _pathSettings.SetValue(Grid.RowProperty, 0);
                  _pathSettings.SetValue(Grid.ColumnProperty, 1);
              }
              if (listView.SelectedItem.Equals(_hideShowTvShowsSettings))
              {
                  SettingsContentPanel.Children.Add(_hideShowTvShowsSettings);
  
                  _hideShowTvShowsSettings.SetValue(Grid.RowProperty, 0);
                  _hideShowTvShowsSettings.SetValue(Grid.ColumnProperty, 1);
              }
          }
      }
  </code></pre>
  
  <p>And the Grid itself:</p>
  
  <pre><code>    &lt;Grid 
          x:Name="SettingsContentPanel" 
          Grid.Row="0" 
          Grid.Column="2" 
          Grid.ColumnSpan="2" /&gt;
  </code></pre>
  
  <p>Is there a way to get rid of the boiler plate code behind and use XAML for this purpose?</p>