Note that there are some explanatory texts on larger screens.

plurals
  1. POMVVM Binding a combobox
    text
    copied!<p>I have a very ordinary ViewModel and I am tring to bind a collection of values to a combobox. The problem is nothing is binding. I have checked the ViewModel constructor and the data is being loaded so I suspect its in my XAML but I just cant find out where.</p> <pre><code>public class OwnerOccupierAccountViewModel : ViewModelBase { readonly UserAccountContext _userAccountContext; readonly LoadOperation&lt;Structure&gt; _loadStructures; #region Properties private ObservableCollection&lt;Structure&gt; _structures; public ObservableCollection&lt;Structure&gt; Structures { get { return _structures; } set { _structures = value; RaisePropertyChanged("Structures"); } } private Structure _selectedStructure; public Structure SelectedStructure { get { return _selectedStructure; } set { _selectedStructure = value; RaisePropertyChanged("SelectedStructure"); } } #endregion public OwnerOccupierAccountViewModel() { _userAccountContext = new UserAccountContext(); if (!DesignerProperties.IsInDesignTool) { _loadStructures = _userAccountContext.Load(_userAccountContext.GetStructuresQuery()); _loadStructures.Completed += new EventHandler(_loadStructures_Completed); } } void _loadStructures_Completed(object sender, EventArgs e) { _structures = new ObservableCollection&lt;Structure&gt;(); foreach (var structure in _loadStructures.Entities) { Structures.Add(structure); } } } &lt;UserControl.Resources&gt; &lt;viewmodel:OwnerOccupierAccountViewModel x:Key='ViewModel'&gt;&lt;/viewmodel:OwnerOccupierAccountViewModel&gt; &lt;/UserControl.Resources&gt; &lt;ComboBox x:Name='cboApartments' ItemsSource='{Binding Structures,Source={StaticResource ViewModel},Mode=TwoWay}' Width='200' /&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