I've three models (Contacts, Notes, Reminders). I want to search all these and produce the filtered result in a single listview and depending upon the selection I've to display the corresponding view(UserControl) to its right.
I want the right way of implementing the design or atleast alternatives to this method that I've tried.
Now I've tried it using a IntegratedViewModel having all the properties from all the three models.
public class IntegratedViewModel
{
ContactModel _contactModel;
NoteModel _noteModel;
public IntegratedViewModel(ContactModel contactModel)
{
_contactModel = contactModel;
} // similarly for other models also
public string DisplayTitle // For displaying in ListView
{
get
{
If(_contactModel != null)
return _contactModel.Name;
If(_noteModel != null)
return _noteModel.Title;
}
}
// All other properties from the three models includin the Name/Title properties for displaying them in the corresponding views(UserControl)
}
Now I set the itemsSource as the List<IntegratedViewModel>
.
I've to now bind the visibility of the views to some properties in the MainViewModel. I tried setting bool properties like IsContactViewSelected
, IsNoteViewSelected
using the setter of SelectedEntity
property which is bound to the ListView's SelectedItem.
public SelectedEntity
{
//get
set
{
oldvalue = _selectedEntity;
_selectedEntity = value;
// now i find the Type of model selected using `oldvalue.ModelType`
// where ModelType is a property in the IntegratedViewModel
// according to the type, i set one of the above bool properties to false
// and do the same for _selectedEntity but set the property to true
// so that the view corresponding to the selectedEntityType is visible
// and others are collapsed
}
}
[[The visibility problem stated here was resolved]]