I'm trying to change the UserControl
in my mainwindow. I'm using devpress's poco viewmodels.
The main window displays except for where the loginView should be it displays "LoginViewModel_xxxxxx"
The LoginView.xaml
is a UserControl
.
I have
MainWindow.xaml
<Grid Row="1">
<ContentControl Content="{Binding CurrentViewModel}"/>
</Grid>
MainWindowViewModel.cs
public virtual object CurrentViewModel { get; set; }
public static MainWindowViewModel Create()
{
return ViewModelSource.Create(() => new MainWindowViewModel());
}
protected MainWindowViewModel()
{
CurrentViewModel = LoginViewModel.Create();
}
LoginViewModel.cs
public static LoginViewModel Create()
{
return ViewModelSource.Create(() => new LoginViewModel());
}
protected LoginViewModel()
{
//unrelated code
}
Try to define a DataTemplate
for the LoginViewModel
:
<ContentControl Content="{Binding CurrentViewModel}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type local:LoginViewModel}">
<local:LoginView />
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.