How to dynamically change the contents of ContentControl in WPF MVVM

Posted by Guna27 under WPF on 12/11/2012 | Points: 10 | Views : 4675 | Status : [Member] | Replies : 0
Hi, I need a solution for dynamically change the contents of Content Control using MVVM


Mainwindow.xaml: This is my xaml code Which contains two resources i.e. two user control.

<Window.Resources>
<ViewModel:Login x:Key="login"></ViewModel:Login>
<DataTemplate x:Key="0">
<Grid>
<my:Tab0 x:Name="gs"></my:Tab0>
</Grid>
</DataTemplate>
<DataTemplate x:Key="1">
<Grid>
<my:Tab1 x:Name="gs_1"></my:Tab1>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<TabControl HorizontalAlignment="Stretch" Name="tabControl1" VerticalAlignment="Stretch">
<TabItem>
<ContentControl>
<ContentControl.ContentTemplate>
<Binding Source="{StaticResource ResourceKey=login}" Path="Contains"></Binding>
</ContentControl.ContentTemplate>
</ContentControl>

</TabItem>
</TabControl>
</Grid>



Login.cs: This View Model Class Path=Contains value

public Login()
{

Contains = "{StaticResource ResourceKey=0}";
}

public string Contains { get; set; }

Guna..............


Responses

(No response found.)

Login to post response