Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Bind to a source rather than DataContext, sources are provided by <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.elementname.aspx" rel="nofollow"><code>ElementName</code></a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.relativesource.aspx" rel="nofollow"><code>RelativeSource</code></a> &amp; <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.source.aspx" rel="nofollow"><code>Source</code></a>, so you can name the View for example and use <code>ElementName</code> to get it as source then the <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.path.aspx" rel="nofollow"><code>Path</code></a> could be <code>DataContext.LookupValues</code> or whatever your property in the model (- the DataContext of the View is your model -) is called.</p> <hr> <p>e.g.</p> <pre class="lang-xml prettyprint-override"><code>&lt;Window ... Name="Window"&gt; &lt;ItemsControl ItemsSource="{Binding Items}"&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Name}" /&gt; &lt;ComboBox ItemsSource="{Binding ElementName=Window, Path=DataContext.Occupations}" SelectedItem="{Binding Occupation}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;!-- ... ---&gt; </code></pre> <hr> <p><strong>Edit:</strong> Your problem seems to be that you do not pass the information you need, consider a design which still grants you access to more than just the SelectedItem of some list, e.g.</p> <pre class="lang-xml prettyprint-override"><code>&lt;Window ... Name="Window"&gt; &lt;ListBox Name="listBox" ItemsSource="{Binding Data}" /&gt; &lt;ContentControl DataContext="{Binding ElementName=listBox, Path=SelectedItem}"&gt; &lt;ComboBox ItemsSource="{Binding ElementName=Window, Path=DataContext.Occupations}" SelectedItem="{Binding Occupation}" /&gt; &lt;/ContentControl&gt; &lt;!-- ... ---&gt; </code></pre> <p>The <code>DataContext</code> of the <code>ContentControl</code> may be the SelectedItem of the ListBox but the ComboBox inside can still reference the DataContext of the Window which should provide the necessary information.</p> <p>This is similar to my first example in that the DataContext inside the DataTemplate is always an item of the collection but you can access external DataContexts using sources in your bindings.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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