I get data from a DataLayer Class into the ViewModel but it doesn't get into the observableCollection that is binded with the listbox in the View.
public class ViewModel : NotifyUIBase
{
public ViewModel()
{
FindImageCommand = new RelayCommand(FindImage);
}
public ObservableCollection<Image> FindVisualReferences { get; set; }
public RelayCommand FindImageCommand { get; private set; }
private void FindImage()
{
string SearchTerm = this.SearchBox;
var dbFunctions = new DatabaseFunctions();
FindVisualReferences = dbFunctions.FindVisualReferences(SearchTerm);
}
}
I've tested the FindVisualReferecences(SearchTerm) Method and it gives the items needed to fill the observableCollection.
I also tested the databinding with the View and that's working to.
When I place the method in the constructor the ObservableCollection gets filled
public ViewModel()
{
var dbFunctions = new DatabaseFunctions();
FindVisualReferences = dbFunctions.FindVisualReferences(SearchTerm);
}
But I need to call the method when the user is gives the FindImageCommand. How can I make this work? I'm really a rookie when it comes to coding.