have defined type board containes public property
observablecollection<column> columns i display use of mvvm pattern. created boardview , bound boardviewmodel. boardviewmodel exposes public property board of type board. boardview contains control itemscontrol sets itemssource={binding board.columns}.
<itemscontrol itemssource="{binding board.columns}"> <itemscontrol.itemtemplate> <datatemplate> <border borderthickness="2" margin="10" borderbrush="#9f9f9f" width="250"> <v:boardcolumnview background="#e3e3e3" /> </border> </datatemplate> </itemscontrol.itemtemplate> boardcolumnview should show properties of column type , works good. problem want create viewmodel boardcolumn, , instead of showing properties of column type want show boardcolumnviewmodel have defined inside column property. how can achieve that? in advance!
you define columns property in boardviewmodel contain collection of boardcolumnviewmodel. this:
public observablecollection<boardcolumnviewmodel> columns { get; private set; } you need initialize property somewhere in boardviewmodel, example:
public boardviewmodel(...) { ... columns = new observablecollection<boardcolumnviewmodel>(board.columns.select(c => new boardcolumnviewmodel(c))); } and bind property, instead of board.columns:
<itemscontrol itemssource="{binding columns}"> <itemscontrol.itemtemplate> <datatemplate> <border borderthickness="2" margin="10" borderbrush="#9f9f9f" width="250"> <v:boardcolumnview background="#e3e3e3" /> </border> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> as general principle in mvvm is not recommended bind directly model. instead should try bind view model. why have problem you've described - because bind public property board, model.
Comments
Post a Comment