0
我有一個UserControl,它包含一個ContentControl,它反過來應該根據設置爲DataContext的視圖模型呈現一個UserControl。WPF ContentControl不顯示用戶控件(應該由DataContext綁定)
的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,並且對我所有的知識都完全一樣。我究竟做錯了什麼?