WPF combobox with name and id
<p>I've got a ComboBox which looks like this:</p>

<pre><code>    &lt;ComboBox x:Name="genreComboBox" ItemsSource="{Binding}" SelectionChanged="genreComboBox_SelectionChanged"&gt;
        &lt;ComboBox.ItemTemplate&gt;
            &lt;DataTemplate&gt;
                &lt;TextBlock Text="{Binding Name}"/&gt;
            &lt;/DataTemplate&gt;
        &lt;/ComboBox.ItemTemplate&gt;
    &lt;/ComboBox&gt;
</code></pre>

<p>I'm binding it to a list of Genres <code>List&lt;Genre&gt;</code>, which have a Name and a genreId. Whenever the selection changes, I update the DataContext of a GridView based on that id. So basically I need to display the name, and use the id in a <code>DataContext=someDB.getStuffById(int genreId);</code></p>

<p>I've tried messing around with <code>getStuffById(genreComboBox.SelectedItem)</code> and <code>getStuffById(genreComboBox.SelectedValue)</code>, setting <code>DisplayMemeberPath="Name"</code> and <code>SelectedValuePath="GenreId"</code>. Most of the time, the named get displayed. </p>

<p>Whatever I try to get that genreId out, I always get a NullReferenceException.</p>

<p>Thank you!</p>