ns12345
ns12345

Reputation: 3105

Wiring views in MVVM Light for WPF

If I have a MainView for now, and inside MainView i have a stackpanel. And now what I want is to plug different views based on Menu item click. How to implement this using MVVM Light?

Would be great if somebody can post a link to a project sample with code or video!!

Upvotes: 2

Views: 958

Answers (2)

ns12345
ns12345

Reputation: 3105

Better way to do this is, define all view's datatemplates in mainview. and then have a itemscontrol(bind it to mainviewmodel's collection of viewmodels property)

Now based on menuitem click, clear that viewmodels collection and add the required view.

Upvotes: 0

L-Four
L-Four

Reputation: 13551

I don't know about MVVM light, but I do something like that without this Light framework as follows:

<!-- Content area that contains user controls for all wizard steps -->
    <Grid Margin="0,3,0,0">
        <Views:CustomerSelection Visibility="{Binding Path=IsCustomerSelectionVisible, Converter={StaticResource boolToVisibilityConverter}}" />
        <Views:CustomerInformation Visibility="{Binding Path=IsCustomerInformationVisible, Converter={StaticResource boolToVisibilityConverter}}" />
        <Views:CustomerPreferences Visibility="{Binding Path=IsCustomerPreferencesVisible, Converter={StaticResource boolToVisibilityConverter}}" />
        <Views:ProjectSelection Visibility="{Binding Path=IsProjectSelectionVisible, Converter={StaticResource boolToVisibilityConverter}}" />
        <Views:KitchenProjectPreferences Visibility="{Binding Path=IsKitchenProjectPreferencesVisible, Converter={StaticResource boolToVisibilityConverter}}" />
        <Views:OtherProjectProperties Visibility="{Binding Path=IsOtherProjectPropertiesVisible, Converter={StaticResource boolToVisibilityConverter}}" />
    </Grid>    

And in the underlying viewmodel I just set the appropriate properties for making one of the usercontrols visible.

Upvotes: 3

Related Questions