【发布时间】:2013-08-06 18:35:22
【问题描述】:
我有一个包含 ScrollViewer 的 UserControl。
<UserControl>
<ScrollViewer Name="ScrollContainerScroller"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Hidden">
<ListBox Name="MyItemsListBox" ItemsSource="{Binding MyItems}"/>
</ScrollViewer>
</UserControl>
在堆栈面板中使用此 UserControl 时,不会显示 ScrollViewer 的滚动条。
<Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <!-- top -->
<RowDefinition Height="*"/> <!-- content -->
<RowDefinition Height="Auto"/> <!-- bottom -->
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" VerticalAlignment="Top">
<Grid Name="ContentButtons" Height="20">
<Button Name="MinimizeContent"/>
<Button Name="MaximizeContent"/>
</Grid>
<ContentControl Name="MyContent"/>
</StackPanel>
<!--
<ContentControl Name="MyContent" Grid.Row="1" VerticalAlignment="Top"/>
-->
<Grid Name="MyBottomControls" Grid.Row="2" VerticalAlignment="Bottom">
<Button Name="Delete" HorizontalAlignment="Left" Style="{StaticResource DeleteButtonStyle}"/>
<Button Name="Close" HorizontalAlignment="Center" Style="{StaticResource CloseButtonStyle}"/>
<Button Name="Hide" HorizontalAlignment="Right" Style="{StaticResource HideButtonStyle}"/>
</Grid>
<!-- shows up at last so the Grid can place it at the very top it in the Z axis -->
<ContentControl Name="MyTop" Grid.Row="0" VerticalAlignment="Top"/>
</Grid>
</Border>
当我移除包装堆栈面板时,滚动查看器会正确显示。
要使滚动条也可以与包装 MyContent-contentcontrol 的附加堆栈面板一起使用,我需要做些什么?
【问题讨论】:
-
使用 Grid 或 DockPanel 代替 StackPanel。但是为什么你需要这个包装呢?
-
其实我忘了这个stackpanel里面还有一些额外的控件应该放在contentcontrol上面。我对此进行了编辑以使其更清晰。