Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Follow these steps</p> <ul> <li>Register <code>MyWindow</code> and <code>MyResource</code> with Autofac. </li> <li>Place <code>IMyResource</code> in the constructor of <code>MyWindow</code> (Yes, you are modifying the code behind, but you are not referring to your container. If you cannot have code in the Code-behind -- perhaps you are a UserControl --then make sure someone is setting the <code>DataContext</code> somewhere)</li> <li>Set <code>DataContext</code> to your concrete instance of <code>IMyResource</code> (in the constructor), or if you are using MVVM, place the instance into your viewmodel (which would also be registered with Autofac).</li> <li>Resolve <code>MyWindow</code></li> </ul> <p>In code:</p> <pre><code>MyWindow(IMyResource myResource) : this() { DataContext = myResource; } </code></pre> <p>If you are using a ViewModel (also registered with Autofac):</p> <pre><code>MyWindow(MyViewModel viewModel) : this() { DataContext = viewModel; } </code></pre> <p>Add this line to your XAML:</p> <pre><code>&lt;Window.DataContext&gt;&lt;local:IMyResource&gt;&lt;/Window.DataContext&gt; </code></pre> <p>Or this:</p> <pre><code>&lt;Window.DataContext&gt;&lt;local:MyViewModel&gt;&lt;/Window.DataContext&gt; </code></pre> <p>And then your markup for <code>ListBox</code> becomes trivial:</p> <pre><code>&lt;ListBox ItemsSource="{Binding}"/&gt; </code></pre> <p>Or, with the viewmodel, as the property <code>Items</code>, for instance, it's just as nice:</p> <pre><code>&lt;ListBox ItemsSource="{Binding Items}"/&gt; </code></pre>
 

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