Does anyone know if the same functionality for displaying views depending on object/viewmodel is applicable to Silverlight 3?
Like this:
<Application.Resources>
<开发者_运维技巧DataTemplate DataType="{x:Type vm:CustomerViewModel}">
<view:CustomerView />
</DataTemplate>
<ContentControl Content="{Binding Path=CurrentView}"/>
public class RootViewModel : BaseViewModel
{
private BaseViewModel _currentView;
public BaseViewModel CurrentView
{
get { return _currentView; }
set
{
_currentView = value;
RaisePropertyChanged("CurrentView");
}
}
public void ShowCustomer()
{
CurrentView = IoC.Resolve<Customerviewmodel>();
}
}
Sorry about the formatting. Can't seem to get it right...
/Johan
If you are using Caliburn, you can use the View.Model attached property on your ContentControl to achieve this.
精彩评论