title: WPF ListBox ListBoxItem Binding
body: <p>I am going through the Sams book "Teach Yourself WPF in 24 Hours". At one point the authors show how you can bind a ListBox's selected-item value to a property. I get that, it's pretty straightforward. But when I try to create my own ListBox control with my own ListBoxItems, I can't seem to get it to work. </p>
  
  <p>The ListBox that works uses a system collection as its ItemsSource property:</p>
  
  <pre><code>&lt;ListBox x:Name="FontList"
           DockPanel.Dock="Left"
           ItemsSource="{x:Static Fonts.SystemFontFamilies}"
           Width="160" /&gt;
  </code></pre>
  
  <p>The value selected from this ListBox is then used in a TextBlock as follows:</p>
  
  <pre><code>&lt;TextBlock Text="Test" 
             FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
             TextWrapping="Wrap"
             Margin="0 0 0 4" /&gt;
  </code></pre>
  
  <p>Notice that the Path is set to SelectedItem. </p>
  
  <p>Now, I wanted to set the FontSize using another ListBox that contains 3 different sizes. Here is what I did:</p>
  
  <pre><code>&lt;ListBox x:Name="Size" &gt;
      &lt;ListBoxItem&gt;10&lt;/ListBoxItem&gt;
      &lt;ListBoxItem&gt;15&lt;/ListBoxItem&gt;
      &lt;ListBoxItem&gt;20&lt;/ListBoxItem&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>And then I added a binding to the Size attribute of the TextBox as follows:</p>
  
  <pre><code>&lt;TextBlock Text="Test" 
             FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
             Size="{Binding ElementName=Size, Path=SelectedItem}"
             TextWrapping="Wrap"
             Margin="0 0 0 4" /&gt;
  </code></pre>
  
  <p>The Size doesn't change when I run the program. So I tried to add the binding I was using for Size to the Text attribute--in order to see its value:</p>
  
  <pre><code>&lt;TextBlock Text="{Binding ElementName=Size, Path=SelectedItem}"" 
             FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
             Size="{Binding ElementName=Size, Path=SelectedItem}"
             TextWrapping="Wrap"
             Margin="0 0 0 4" /&gt;
  </code></pre>
  
  <p>I see that it is changing as I click the Size ListBox, but I also see that the SelectedItem is displaying as this (when I click the 15 entry):
  System.Windows.Controls.ListBoxItem:15</p>
  
  <p>My questions:
  1) What is the actual value being returned by the Path called SelectedItem? Is it "System.Windows.Controls.ListBoxItem:15" or is it "15"? If it's not 15, how can I specify a Path that returns just 15 and not System.Windows.Controls.ListBoxItem:15?</p>
  
  <p>2)Why does the FontFamily SelectItem work? I realize that the FontList is coming from a System collection of font names, but it is unclear to me why the ListBox isn't returning a collection of ListBoxItems as text. If my ListBox's Path reference is returning a SelectedItem object of type ListBoxItem, then I would think I could use a Path of SelectedItem.Value or something like that--but it doesn't work and there is no Intellisense to help me.</p>
  
  <p>I want to get THIS example working because it will help clear-up some misunderstandings I have. Please don't refactor the solution to get it to work some other way unless it's entirely impossible for me to have a Path reference that will give me just the numeric portion of my Size ListBoxItem that is selected.</p>