Building ViewModels based on nested Model Entities in WPF and MVVM Pattern

后端 未结 4 1770
南方客
南方客 2021-02-05 17:22

I have a problem understanding how to build view models based on the following models

(I simplified the models to be clearer)

public class Hit
{
   publi         


        
4条回答
  •  死守一世寂寞
    2021-02-05 17:40

    One solution I've been considering, although I'm not sure if it would work perfectly in practice, is to use converters to create a viewmodel around your model.

    So in your case, you could bind Tracks directly to (as an example) a listbox, with a converter that creates a new TrackViewModel from the Track. All your control would ever see would be a TrackViewModel object, and all your models will ever see is other models.

    I'm not sure about the dynamic updating of this idea though, I've not tried it out yet.

提交回复
热议问题