C# WPF ContentControl未显示用户控件(应该由DataContext绑定)

C# WPF ContentControl未显示用户控件(应该由DataContext绑定),c#,wpf,xaml,contentcontrol,C#,Wpf,Xaml,Contentcontrol,我有一个UserControl,它包含一个ContentControl,根据设置为DataContext的视图模型,ContentControl应该显示一个UserControl XAML: <UserControl.Resources> <DataTemplate DataType="{x:Type pcViewModels:SystemPCViewModel}"> <controls:SystemPCControl /> &

我有一个UserControl,它包含一个ContentControl,根据设置为DataContext的视图模型,ContentControl应该显示一个UserControl

XAML:

<UserControl.Resources>
    <DataTemplate DataType="{x:Type pcViewModels:SystemPCViewModel}">
        <controls:SystemPCControl />
    </DataTemplate>
    <DataTemplate DataType="{x:Type pcViewModels:ChipPCViewModel}">
        <controls:ChipPCControl />
    </DataTemplate>
    <!-- Left out other definition, I guess you get the point -->
</UserControl.Resources>

<Grid Background="Aqua">
      <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <ScrollViewer Background="Blue">

        <ContentControl DataContext="{Binding CurrentContent}"/>

    </ScrollViewer>

    <StackPanel 
        Grid.Row="1"
        Orientation="Horizontal" FlowDirection="RightToLeft">

        <Button 
            Width="150" Height="50"
            Content="Configure"
            VerticalAlignment="Center"
            Command="{Binding CurrentContent.ConfigureCommand}" />
    </StackPanel>

</Grid>

我让网格和ScrollViewer的背景看起来很难看,只是为了确保它是可见的。所有这些都是可见的,我可以看到视图模型是DataContext(按钮也可以正常工作)

我以前使用过ContentControl,据我所知,就是这样。我做错了什么?

您必须设置您的属性。您可以执行以下任一操作:

<ContentControl DataContext="{Binding CurrentContent}" Content="{Binding}" />


<ContentControl Content="{Binding CurrentContent}" />