title: Data binding access in xaml vs in code behind - Linq to XML?
body: <p>I have a listbox that binds to and displays the Name elements from an XML file. When a listbox item is selected, I want to display the Price value associated with this item in a textblock. How do I retrieve the Price programmatically (meaning not in the xaml file but in code behind)? Thanks.</p>
  
  <p>XML file has these nodes:</p>
  
  <pre><code>&lt;Product&gt;
      &lt;Name&gt;Book&lt;/Name&gt;
      &lt;Price&gt;7&lt;/Price&gt;
  &lt;/Product&gt;
  </code></pre>
  
  <p>I use Linq and do the <code>select</code> with an <strong>anonymous type</strong>. If the easiest way to access the field programmatically is through a named type, please show me how.</p>
  
  <p>Here's how I bind in xaml (using a data template for each listbox item that contains):</p>
  
  <pre><code> &lt;TextBlock Text = "{Binding Name}" /&gt;
  </code></pre>
  
  <p>Here's the code-behind function where I want to retrieve the Price:</p>
  
  <pre><code>        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
      { 
         // how do I get the value of Price of the selected item here?
      }
  </code></pre>
  
  <p><strong>Please note that I want to access Price in this function, NOT in xaml!</strong></p>