带有嵌套扩展器的 ListView 不会折叠
这个问题与其他相同未回答的问题。
当 Expander 展开时,外部 ListView 会增大,为扩展器内容腾出空间,但是当 Expander 折叠时,视图不会强制要调整 ListView 的大小。
减少代码,后面有注释:
<!--<StackPanel>-->
<ItemsControl>
<!-- ParameterGroupView -->
<Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4">
<ListView HorizontalContentAlignment="Stretch">
<Expander Header="Expander A" IsExpanded="False">
<ListView HorizontalContentAlignment="Stretch">
<!-- TextView -->
<TextBlock >Content A</TextBlock>
<TextBlock >Content B</TextBlock>
</ListView>
</Expander>
</ListView>
</Border>
</ItemsControl>
<!--</StackPanel>-->
我在 ItemsControl 或 StackPanel 中有 ParameterGroupView,因为实际上有很多 ParameterGroupView条目。交换到 StackPanel 不会改变行为。
删除 Boarder 不会影响行为,但拥有它有助于仅使用单个 ParameterGroupView 显示行为。
外部 ListView 中可以有许多 Expander 部分,并且 Expander 内部 ListView 内部可以有许多实体。
外部的ListView和Expander将取代TreeView,它用于具有可折叠节点的列表,但是TreeView< /em> 网格的内部使用,意味着 TextView 项目被水平压缩,就像删除以太 HorizontalContentAlignment="Stretch" 属性一样。
因此,如果有另一种方法来包装/连接所有这一切,我也会很高兴。
这是一个问题,因为我们的 TextView 块很大并且有很多 Expander。
编辑:使用 TextView 是因为代码是数据绑定的,因此可以动态地组合在一起。因此 ListView 的任何替代品都需要某种形式的 ItemsSource
This question is the same as this other unanswered question.
When the Expander is expanded the outer ListView grows to make space for the expanders contents, but when the Expander is then collapsed the view does not force the ListView to resize.
Reduced code, with notes after:
<!--<StackPanel>-->
<ItemsControl>
<!-- ParameterGroupView -->
<Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4">
<ListView HorizontalContentAlignment="Stretch">
<Expander Header="Expander A" IsExpanded="False">
<ListView HorizontalContentAlignment="Stretch">
<!-- TextView -->
<TextBlock >Content A</TextBlock>
<TextBlock >Content B</TextBlock>
</ListView>
</Expander>
</ListView>
</Border>
</ItemsControl>
<!--</StackPanel>-->
I have the ParameterGroupView in a ItemsControl or StackPanel because there is actually many ParameterGroupView entries. Swapping to a StackPanel does not change the behaviour.
Removing the Boarder does not affect the behaviour, but having it helps show the behaviour with only a single ParameterGroupView.
There can be many Expander sections in the outer ListView, and the Expander can have many entities inside the inner ListView.
The outer ListView and Expander is to replace a TreeView, that was used to have a list of collapsible nodes, but the TreeView's internal use of grids, means the TextView items were squashed horizonatlly, the same as if you remove ether HorizontalContentAlignment="Stretch" attributes.
So if there is another way to wrap/wire all this up, I'll be also happy.
This is a problem because our TextView blocks are large and there are many Expanders.
Edit: TextView is used as the code is data-bound, and thus dynamically put together. So any replacement for ListView would need some form of ItemsSource
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了解决方案,它详细说明了问题所在的位置。
ItemControl 接受 ItemsSource 并自动调整大小。因此,用 ItemControl 替换两个 ListView 会导致嵌套折叠。
但没有滚动,因此用 ScrollViewer 包裹外部 ItemControl,可以再现完整的所需效果。
我正在边框和双边框部分中使用双扩展器进行测试。
Found the solution, and it details where in the question already.
ItemControl accepts an ItemsSource and auto resizes. So replacing the two ListViews with ItemControls gets the nested collapsing.
But there is no scrolling, so wrapping the outer ItemControl with a ScrollViewer, reproduces the complete desired effect.
I was testing with double Expanders in the Border and double Border sections.
这里要做的最明显的事情是将扩展器放在列表视图之外的容器中:
容器围绕内容调整大小就可以了。
如果你绝对必须将它放在 ListView 中(这是可能的),那么我不知道有什么方法可以让 ListView 在增长后轻松调整大小(除了设置整个事物的显式大小之外,这是笨拙且无用的) 。如果是这种情况,那么如果您希望能够看到它,您可能必须使用可控列表框来显示所有打开的扩展器,或者以不同的方式显示内容(例如在弹出窗口中,也许?)一目了然。
The most obvious thing to do here is to put the expanders in a container other than a listview:
The container resizes around content just fine.
If you absolutely must have it in a ListView (which is possible) then I don't know of a way to get a ListView to resize easily once it's grown (beyond setting explicit sizes of the whole thing, which is clumsy and not useful). If thats the case then it's possible that you'll have to use a controllable listbox to display all the open expanders, or display the content in a different way (like in a popup, maybe?) if you want to be able to see it all at a glance.