Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, this:</p> <pre><code>dgFruit.ItemsSource = "{Binding}" </code></pre> <p>should set the items source to a string containing the word Binding in braces. This is almost certainly not what you want (in fact, if you do this you should end up with a grid with nine rows, one for each character in the string!). You can set the ItemsSource in the XAML, or the code behind, but you shouldn't do both. Try the following:</p> <pre><code>&lt;toolkit:DataGrid Name="dgFruit" ItemsSource="{Binding}"&gt; ... &lt;/toolkit:DataGrid&gt; </code></pre> <p>And then in your visual's constructor:</p> <pre><code>... InitializeComponents(); this.DataContext = fruitList; ... </code></pre> <p>Now the data context for your whole visual is the List&lt;Fruit&gt;, and the ItemsSource of your grid is set to be the same object. I'm assuming here that fruitList is a field of the visual itself.</p> <p>The bindings for your columns should look something like:</p> <pre><code> &lt;toolkit:DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="5*" /&gt; &lt;toolkit:DataGridComboBoxColumn Header="Color" ItemsSource="{Binding Source={StaticResource AllColors}}" SelectedValueBinding="{Binding Path=Color}" TextBinding="{Binding Path=Color}" Width="5*" /&gt; </code></pre> <p>Where AllColors is defined as a resource (in this case):</p> <pre><code>&lt;x:Array x:Key="AllColors" Type="sys:String"&gt; &lt;sys:String&gt;Orange&lt;/sys:String&gt; &lt;sys:String&gt;Yellow&lt;/sys:String&gt; &lt;/x:Array&gt; </code></pre> <p>This should get you started.</p>
 

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