Scrollviewer 中的扩展器:折叠扩展器后 Scrollviewer 不收缩
Posted
技术标签:
【中文标题】Scrollviewer 中的扩展器:折叠扩展器后 Scrollviewer 不收缩【英文标题】:Expanders in Scrollviewer: Scrollviewer not shrinking after collapsing the expanders 【发布时间】:2013-04-19 14:19:01 【问题描述】:我有一个网格。该网格包含一个滚动查看器,该滚动查看器包含一个列表框,其项目是扩展器。当展开扩展器直到它们超过 UserControl 的垂直可用高度时,滚动查看器的滚动条会正确显示。当我再次折叠扩展器时,滚动查看器的滚动条保持不变!它不会像预期的那样再次缩小或消失。
我已经尝试了一些不同的网格行设置(“Auto”、“*”)和不同的垂直对齐设置(Top、Stretch、...)
如何在折叠扩展器后让滚动查看器再次缩小?
<UserControl x:Class="Expanderin_Scroller.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
d:DesignWidth="440"
d:DesignHeight="300">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="ScrToolbox"
Grid.Row="1"
VerticalAlignment="Top">
<ListBox x:Name="Toolbox">
<telerik:RadExpander Header="Expander 1">
<StackPanel>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
</StackPanel>
</telerik:RadExpander>
<telerik:RadExpander Header="Expander 2">
<StackPanel>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
</StackPanel>
</telerik:RadExpander>
<telerik:RadExpander Header="Expander 3">
<StackPanel>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
</StackPanel>
</telerik:RadExpander>
<telerik:RadExpander Header="Expander 4">
<StackPanel>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
<TextBlock>Hello</TextBlock>
</StackPanel>
</telerik:RadExpander>
</ListBox>
</ScrollViewer>
</Grid>
</UserControl>
【问题讨论】:
您确定您不会只使用Accordion
控件吗?或者,您是否尝试过使用ListBox
ScrollViewer
而不是HandlesScrolling
= True?
我有特殊样式的控件(Scrollviewer 和扩展器)。所以我需要使用上面示例中的控件。没有别的想法?滚动查看器必须可以根据其内容进行调整...
【参考方案1】:
我可以在 Telerik 人的帮助下解决这个问题:
这个问题是由 ListBox 行为,特别是它的 ItemsPanel 引起的。为了更新 ListBox 的大小及其内容的大小,您可以将 ListBox.ItemsPanel 设置为 StackPanel。
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
现在列表框会随内容一起调整大小。
【讨论】:
以上是关于Scrollviewer 中的扩展器:折叠扩展器后 Scrollviewer 不收缩的主要内容,如果未能解决你的问题,请参考以下文章