Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is definitely possible and you're on the right track using an <code>AncestorType</code> binding for the <code>ItemsSource</code>. But I think I see a couple of mistakes.</p> <p>First, your <code>ItemsSource</code> should be binding to <code>DataContext.Owners</code>, not <code>DataContext.Houses</code>, correct? You want the viewmodels' collection of Owners to show up in the drop-down. So first, change the <code>ItemsSource</code> and take out the Selection-related stuff, like this:</p> <pre><code>&lt;ComboBox ItemsSource="{Binding Path=DataContext.Owners, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" DisplayMemberPath="Name" /&gt; </code></pre> <p>Now test it out and make sure the <code>ItemsSource</code> is working correctly. Don't try messing around with selection until this part works.</p> <p>Regarding selection, I think you should be binding <code>SelectedItem</code> only - not <code>SelectedValue</code>. For this binding, you <strong>do not</strong> want a <code>RelativeSource</code> binding - the DataContext will be a single <code>House</code> so you can bind directly its <code>HouseOwner</code>. My guess is this:</p> <pre><code>&lt;ComboBox ItemsSource="{Binding Path=DataContext.Owners, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" DisplayMemberPath="Name" SelectedItem="{Binding HouseOwner}" /&gt; </code></pre> <p>Finally, for debugging bindings you can <a href="http://www.falconerdevelopment.com/2011/03/17/debugging-wpf-silverlight-binding-errors-visual-studio/" rel="nofollow">see the Visual Studio Output window</a> or step up to a tool like <a href="http://snoopwpf.codeplex.com/" rel="nofollow">Snoop</a> or <a href="http://wpfinspector.codeplex.com/" rel="nofollow">WPF Inspector</a>. If you plan on doing a lot of WPF, I would recommend getting started with Snoop sooner than later.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload