下面的ScrollViewer不工作。我尝试了所有我能在这个网站上找到的东西,包括:将ScrollViewer嵌入到网格中,将ScrollViewer的孩子嵌入到网格中,将ScrollViewer嵌入到具有固定高度的StackPanel中,设置/绑定ScrollViewer的高度,所有这些都没有用…谁告诉我恢复理智的方法??
注意,下面的XAML只是为了显示窗口的结构。我删除了所有数据。
<Window>
<Window.Resources>
<DataTemplate x:Key="ColoringLabels">
</DataTemplate>
</Window.Resources>
<DockPanel>
<StatusBar DockPanel.Dock="Top">
<StatusBarItem>
</StatusBarItem>
</StatusBar>
<StackPanel Orientation="Vertical">
<TextBox/>
<Button>Hello World!</Button>
<ScrollViewer>
<StackPanel Orientation="Vertical">
<Label>Hola Mundo!</Label>
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{StaticResource ColoringLabels}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Source="{Binding}"ItemTemplate="{StaticResource ColoringLabels}"/>
</StackPanel>
</ScrollViewer>
<TextBlock/>
</StackPanel>
</DockPanel>
</Window>
编辑:
我通过将XAML更改为:
<Window>
<Window.Resources>
<DataTemplate x:Key="ColoringLabels">
</DataTemplate>
</Window.Resources>
<DockPanel>
<StatusBar DockPanel.Dock="Top">
<StatusBarItem>
</StatusBarItem>
</StatusBar>
<ScrollViewer>
<StackPanel Orientation="Vertical">
<TextBox />
<Button>Hello World!</Button>
<StackPanel Orientation="Vertical">
<Label>Hola Mundo!</Label>
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{StaticResource ColoringLabels}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Source="{Binding}"ItemTemplate="{StaticResource ColoringLabels}"/>
</StackPanel>
<TextBlock/>
</StackPanel>
</ScrollViewer>
</DockPanel>
</Window>
为什么现在有效????也许是因为ScrollViewer现在可以填充DockPanel的最后一个子位置了????