tags:

views:

99

answers:

1

Hi,

I've started using mvvm-light toolkit , and new to WPF.

My question is: I want to create an pplication where the main window includes a grid with 2 columns 1 col command and col2 will display views when each command will be pressed. i want the views to be created on command and colsed from it's own view.

I've tried to figure out how to do it but with no success.

I don't know how to write this kind of funconality using the mvvm light.

I just know how to create main window with mainview and another view creted already on load.

Please help me out..

I'm using 2008 WPF3.5

Shirly. Make me happy today.. i've just started the week!!!

ThankU. I have done it and get as a result the Tostring() of the current ViewModel "LU.ViewModel.AllChannelsViewModel" and not the real view.

the View i want to load is : I'm using the mvvm-light

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="30" />
        <RowDefinition Height="30" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Button Grid.Row="0" Height="22" HorizontalAlignment="Right" Margin="8,4,0,0" Name="closebutton" VerticalAlignment="Top" Width="100" Command="{Binding CloseCommand}">Close</Button>
    <Button Grid.Row="1" Height="22" HorizontalAlignment="Left" Margin="8,4,0,0" Name="button1" VerticalAlignment="Top" Width="100" Command="{Binding GetChannelsCommand}">Load Channels</Button>
    <Button Grid.Row="1" Height="22" HorizontalAlignment="Right" Margin="8,4,0,0" Name="button2" VerticalAlignment="Top" Width="100" Command="{Binding NewChannelCommand}">New Channel</Button>
    <dg:DataGrid   Grid.Row="2"  ItemsSource="{Binding AllChannelsData}" Margin="0,30,0,0" />


</Grid>

What do i miss here? How can i show the real view i want and not the name of the viewmodel?

Shirly

+2  A: 

I don't know if there is anything specific to do that with MVVM Light, but a common way to create a view in MVVM is to create a ContentControl that is bound to a property of the ViewModel. When you affect a new ViewModel to that property, the ContentControl renders it using the DataTemplate that matches the ViewModel's type :

<!-- In resources -->
<DataTemplate DataType="{x:Type vm:FooViewModel}">
    <v:FooView />
</DataTemplate>

<DataTemplate DataType="{x:Type vm:BarViewModel}">
    <v:BarView />
</DataTemplate>
...

<!-- In the main view -->

<ContentControl Content="{Binding Current}" />
Thomas Levesque