c# - One ViewModel containing a collection of ViewModels, different Views depending on value of ViewModel property -


i new mvvm-pattern, , trying out caliburn.micro on project.

i want have 1 viewmodel (which contains collection of viewmodels) shared multiple views, each view displays items have value on 1 of it's properties.

to specific, using service allows me monitor different values update frequently. object of type monitoreditem, contains property of type datavalue, in turn contains object value , property value's datatype.

so far have monitoreditemviewmodel uses service's monitoreditem class it's model, , monitoreditemsviewmodel contains bindablecollection<monitoreditemviewmodel> monitoreditems, , commands adding/removing items.

i have monitoreditemsview can see items monitoring.

how go splitting view, can have monitoreditems datavalue integer/float/double displayed in 1 area in window, boolean values displayed somewhere else etc?

don't in view, instead expose different collections on viewmodels according need filter.

this can done either known collections, e.g.

public observablecollection<monitoreditemviewmodel> itemswherefooisbar ... public observablecollection<monitoreditemviewmodel> itemswherefooisntbar ... 

or more generically return filtered collections on demand

public observablecollection<monitoreditemviewmodel> getitems(func<datavalue, bool> matches) {    //filter collection     return ... allitems.where(x=>matches(x))... ; } 

and call via

getitems(x=>x.foo == bar) 

the problem going have when items change , should switch collection collection. if using reactiveui incredibly easy can use rx trigger built in item tracking , use .createderivedcollection(...) build new collections automatically (hint, hint :-))

if not have few choices.

  • you can derive class observablecollection being notified via collectionchanged when new items added or removed, or notified when properties of items change well.
  • or make itemviewmodel immutable properties never change, instead drop old item , add updated 1 correct collection.

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -