1
votes

Big Picture goal: I'd like to edit models in a Data window that is full of property pages that edit the given model. I'd like to mark the models with multiple interfaces that they satisfy. For each interface, an associated propertypage viewmodel and view exist.

What I'm struggling with is how can I resolve the Collection of property page viewmodels from a given model that satisfies 1-N interfaces.

I was wondering if I could put a property page view model factory within the container? I would try to resolve a collection of property page viewmodels from the container, and the container would use the factory to correctly generate the viewmodels needed. I could hand that collection of viewmodels to a data window, which would use the ViewModelToViewConverter to generate the views of the viewmodels.

Is it possible to register a factory with the container? Is this the best way to achieve this goal? I suppose I could have the data window's viewmodel handle converting the model to a collection of viewmodels, but that feels out of scope.

1

1 Answers

0
votes

I think you can create a list (ObservableCollection) of models that you want to edit in the main view model. Then you create an ItemsControl with a custom view as data template:

<ItemsControl ItemsSource="{Binding MyModels}">
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <myViews:ModelEditorView />
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>

Then you have this view model which is automatically created for your ModelEditorView:

public class ModelEditorViewModel : ViewModelBase
{
    public ModelEditorViewModel(MyModel model /*, other dependency injections here*/)
    {
        Argument.IsNotNull(() => model);

        Model = model;
    }

    public MyModel Model { get; private set; }
}

Then everything will be created for you automatically.