Where should 'call command on property change' functionality go?
c#, mvvm, wpf
Solution
A more appropriate solution in my opinion would be to call the command from the setter of your SearchString property on the ViewModel.
Problem
I have a viewModel with these three properties: ``` string searchString; ObservableCollection<Company> ListedItems; ICommand SearchCommand; ``` It represents a searchable list of companies in my database. `SearchCommand` searches the database based on the value of `searchString`, and then populates `ListedItems` with the results. `SearchString` is bound to a textbox, while `SearchCommand` is bound to a button. I want to make it so that as the user types into the text box, `SearchCommand` is automatically executed without the user having to click the button. At the moment, I do this via my viewModel: ``` public ListViewModel() { this.PropertyChanged += delegate(object o, PropertyChangedEventArgs e) { if (e.PropertyName == "SearchString") SearchCommand.Execute(null); }; } ``` Is this correct? Would it be better to have this functionality in the view? If so, how is that achieved?