If I have a MainView for now, and inside MainView i have a stackpanel. And now what I want is to plug differen开发者_开发技巧t 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!!
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.
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.
精彩评论