在WPF中,我正在使用MVVM模型。
我有一个视图,其中包含一个Dockpanel,我想通过绑定动态添加StackPanels,为所有发现的硬盘添加Label和TextBox。
因此,我的XAML如下所示:
应该有四个标签和文本框,但只显示第一个标签和文本框。为什么?
我有一个视图,其中包含一个Dockpanel,我想通过绑定动态添加StackPanels,为所有发现的硬盘添加Label和TextBox。
因此,我的XAML如下所示:
<DockPanel Grid.Row="1" HorizontalAlignment="Stretch" Margin="5">
<ItemsControl ItemsSource="{Binding Harddisks}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="2.5,0,0,0">
<Label Content="{Binding Path=Label}" />
<TextBox Text="{Binding Path=GB_Free}" Width="100" IsReadOnly="True"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
应该有四个标签和文本框,但只显示第一个标签和文本框。为什么?