0

I apologize for the crappy title, I wasn't quite sure how to summarize what I'm trying to do.

My scenario: I am refactoring an existing WinForms application to WPF and MVVM. I'm currently working on a module that provides search functionality for a database comprised of many different tables such as Contact, User, Case, Product, etc. In code-behind there are classes which provide an Object for each. I have written wrapper classes for each of the searchable table Objects that expose only the properties a user would want/need to see in the search results for each type of Object, for binding to a DataGrid.

Once these search results exist, they need to be displayed in a combination of Tab Controls and Data Grids, like so:

enter image description here

Because of some use cases, I need to be able to create an individual display Tab+DataGrid for the results of every single search that is performed. I cannot have a single tab for each type of search that is shown/hidden as needed.

I'm not sure how to proceed from where I currently am to the goal pictured and described above. Thanks for any help anyone can provide.

0

1 Answer 1

2

Not sure I entirely understand your question, but it looks to me that it might be a candidate for datatemplateselector.

Basically, you use an ItemsControl bound to your result collection and then - using a datatemplateselector - you swap in the appropriate template to display the item based upon a code inspection.

That will let you present all the results in a single list.

If you want to display your results in a tabs, I would present a collection of each result type in your viewmodel. So you have a Users collection and a seperate Products collection. Then you can bind individual data grids to each template.

If you want to then hide the tabs when no results are present, add a data trigger using the expression.interactivity namespace to trigger the visibility of each tab page based on its respective collection count.

One more thing, if you want to create tab items dynamically, i.e. One tab for each search - the tab control has an ItemSource property. If you group each search result into an object an expose an observable collection of that object, you can bind that to your tab control and have it create tab items for each search result. Just make that object contain a collection of actual results and you should be able to create a itemscontrol as mentioned here already.

Sorry if this appears a bit of a mind dump, but like I said - not sure if I entirely get the question :)

Rather then chuck a load of code snippets in, there a plenty of samples just a google away if anything sounds helpful.

Sign up to request clarification or add additional context in comments.

4 Comments

I'll look into some of what you suggested, however, there is a part of my question you're misunderstanding. I can't just have one tab for each type of search that is hidden/shown as needed. I need a single tab for each and every set of search results - there are a number of use cases where users will need to be able to perform and view the results of multiples of the same type of search. I'll try to update my question to make that more clear.
I have edited to include some more tips I think are appropriate.
Can you link me to a good example of what you described with the Tab Control's ItemSource bit?
tap-source.com/mvvm-tabcontrol - this is good clear example, you should hopefully from this be able to extend the itemtemplate to meet your requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.