使用devexpress mvvm更改WPF用户控件

时间:2018-08-16 01:27:29

标签: c# wpf devexpress devexpress-windows-ui devexpress-wpf

我正在尝试在主窗口中更改UserControl。 我正在使用devpress的poco视图模型。

显示主窗口,除了应显示loginView的位置 “ LoginViewModel_xxxxxx”

LoginView.xamlUserControl

我有

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
}

1 个答案:

答案 0 :(得分:1)

尝试为DataTemplate定义一个LoginViewModel

<ContentControl Content="{Binding CurrentViewModel}">
    <ContentControl.Resources>
        <DataTemplate DataType="{x:Type local:LoginViewModel}">
            <local:LoginView />
        </DataTemplate>
    </ContentControl.Resources>
</ContentControl>