1
votes

I have a question regarding multiple user controls views with the same view model type. I can't seems to find specific answers for my confusion but this is quite speculative.

I have.

    <StackPanel Orientation="Vertical">

        <TextBlock Text="Signature Summary" FontSize="14" FontWeight="Bold" TextAlignment="Center" Height="30"/>

        <my:ParameterFileSummaryView DataContext="{Binding ParamterFile1ViewModel}"/>

        <my:ParameterFileSummaryView DataContext="{Binding ParamterFile2ViewModel}"/>

        <my:ParameterFileSummaryView DataContext="{Binding ParamterFile3ViewModel}"/>

        <my:ParameterFileSummaryView DataContext="{Binding ParamterFile4ViewModel}"/>

        <my:ParameterFileSummaryView DataContext="{Binding ParamterFile5ViewModel}"/>

    </StackPanel>

the stack panel is a container inside a main view which has a dependancy property view model datacontext used for a Prism/Unity IoC architecture.

These are therefore binding the datacontect for these individual views to properties of the interface of the main view via another interface.

It all seems to work ok and the binding of the elements in the ParameterFileSummaryView bind nicely to the values set on the, say for the first one, ParamterFile1ViewModel.

Which is exactly what I want. But of cource these ViewModels are built within the ViewModel of the main window and not out of the Unity container.... It all feels a little bit hacky. Is there a cleaner way to implement what I am attempting.

Apologies if it is really a moot question... but I can't see the wood for the trees. If the question confuses I will add edits, please be patient I am not an expert :) .

1
So make the ViewModel of the main window instantiate those ViewModels by resolving them from the container. You almost got there yourself I think. - Jon
For some reason I was thinking that all of my concrete classes built by the container and contracted by my interface, where singletons by definition. But of course I get to choose if this is true or not... I don't think i have a reference to the container in my main view model, maybe I could pass it multiple 'sub' view models in it's constructor? - tigerswithguitars
That could work as well (letting the container inject them automatically). - Jon
Seems to work ok... Thanks for the sanity check! - tigerswithguitars

1 Answers

0
votes

Question answered by myself and sanity checked by @Jon... Sorry SO for cluttering your questions board.