If I’m using the MVVM pattern – this one for my WPF application

And my project requires a search function on different sources – say clients, accountants, cases.

What would be the best way to go about it so that I only have one search view and the search results shown in the ListView are ‘dynamic’ in that they could be result for clients or accountants or cases

Should I have a base search view model and specific view models for clients, accountants, cases that then somehow set as the datacontext for the search view


try to build the grid dynamically in a code behind for the search and then somehow get the data back into the view model without the search view knowing about the view model.

For clarification

The searches are separate and will not need to be combined, I would only every return results for clients or accountants or cases.


Map a generic View Model to whatever you are searching on. The field names in the View Model will always be the same, i.e. ID, Title, Description or something like that.

For example, if you are searching for clients, map ID in your ViewModel to ClientID in your model, Title to ClientName, and Description to ClientProfile.

If you need to display different entities in the same search (e.g. clients and cases together), you will need to do multiple searches and UNION the results, or maintain a denormalized table of search descriptions.

  • added clarification to question
    – Rob
    Jul 13 '11 at 15:29

I would build a grid for each search type case. e.g.



result 1 result 2 result 3


result 1 result 2 result 3


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.