title: Getting text as string from selected item in ListBox
body: <p>I have a ListBox, and I'm trying to get the value of the selected item as a string, but nothing I try seems to work. Here's how I have setup the ListBox and data for it:</p>
  
  <pre><code>public class Thing
      {
          public string Name { get; set; }
          public string Manufacturer { get; set; }
      }
  System.Collections.ObjectModel.ObservableCollection&lt;Thing&gt; deviceList;
  
  deviceList = new System.Collections.ObjectModel.ObservableCollection&lt;Thing&gt;()
          {
              new Thing{ Name="Amaze", Manufacturer="HTC"},
              new Thing{ Name="One X", Manufacturer="HTC"},
              new Thing{ Name="One X+", Manufacturer="HTC"},
              new Thing{ Name="Moto X", Manufacturer="Motorola"},
              new Thing{ Name="Moto G", Manufacturer="Motorola"},
              new Thing{ Name="OnePlus One", Manufacturer="Other"},
          };
  System.ComponentModel.ICollectionView view = System.Windows.Data.CollectionViewSource.GetDefaultView(deviceList);
  view.GroupDescriptions.Add(new System.Windows.Data.PropertyGroupDescription("Manufacturer"));
  view.SortDescriptions.Add(new System.ComponentModel.SortDescription("Manufacturer", System.ComponentModel.ListSortDirection.Ascending));
  view.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending));
  phoneListBox.ItemsSource = view;
  </code></pre>
  
  <p>Here's the XAML:</p>
  
  <pre><code>&lt;ListBox Name="phoneListBox" Height="178" Margin="-25,25,5,0" SelectionChanged="phoneListBox_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Visible"&gt;
   &lt;ListBox.GroupStyle&gt;
     &lt;GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/&gt;
   &lt;/ListBox.GroupStyle&gt;
   &lt;ListBox.ItemTemplate&gt;
    &lt;DataTemplate&gt;
     &lt;TextBlock Text="{Binding Name}"/&gt;
    &lt;/DataTemplate&gt;
   &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>The most common way I've seen is to do:</p>
  
  <pre><code>string selected = phoneListBox.GetItemText(phoneListBox.SelectedValue);
  </code></pre>
  
  <p>but VS doesn't recognize GetItemText as a property of ListBox at all.</p>
  
  <p>I've also tried:</p>
  
  <pre><code>string selected = phonelistBox.SelectedItem.ToString();
  </code></pre>
  
  <p>but it doesn't return the actual text of the item.</p>
  
  <p>I'm using WPF with MahApps.Metro UI, so it's possible there ListBox has different attributes than the generic one, but I don't know how that would change things. Any suggestions are appreciated.</p>