ListView控件嵌套扩展没有崩溃
这个问题是与此相同的其他unanswered问题。
This question is the same as this other unanswered question.
当的扩展的扩展外的的ListView 的增长,使空间的扩展内容,但是当的扩展的随后崩溃的观点不强制ListView控件来调整。
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.
减少code,与笔记后:
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>-->
我有 ParameterGroupView 的中的的ItemsControl 或的StackPanel 的,因为有很多实际的 ParameterGroupView 的条目。交换到的的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.
拆卸的条纹的,不影响行为,但有它有助于展示与行为只有一个单一的 ParameterGroupView 的
Removing the Boarder does not affect the behaviour, but having it helps show the behaviour with only a single ParameterGroupView.
可以有很多的扩展的部分外层的的ListView 的和的扩展的可以有内许多实体内部的的ListView 。
There can be many Expander sections in the outer ListView, and the Expander can have many entities inside the inner ListView.
外的的ListView 的和的扩展的是替换的的TreeView 的,使用的具有可折叠的节点列表,但 TreeView控件的的内部使用网格,意味着TextView的项目被压扁horizonatlly,一样的,如果你删除甲醚的 HorizontalContentAlignment =拉伸的属性。
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.
这是一个问题,因为我们的的TextView 的块大,有很多的扩展的秒。
This is a problem because our TextView blocks are large and there are many Expanders.
编辑:的TextView 的用作code是数据绑定,从而动态地放在一起。因此,任何替代的ListView将需要某种形式的的的ItemsSource 的
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
找到了解决办法,而且它已经的问题详细说明了。
Found the solution, and it details where in the question already.
的 ItemControl 的接受一个的的ItemsSource 的和经销商调整大小。因此,与* ItemControl * S被嵌套倒塌替换两个*的ListView * S。
ItemControl accepts an ItemsSource and auto resizes. So replacing the two *ListView*s with *ItemControl*s gets the nested collapsing.
但没有滚动,所以包装外的 ItemControl 的用的的ScrollViewer 的,再现了完整的预期效果。
But there is no scrolling, so wrapping the outer ItemControl with a ScrollViewer, reproduces the complete desired effect.
<ScrollViewer
VerticalScrollBarVisibility="Auto">
<ItemsControl>
<!-- ParameterGroupView -->
<Border
BorderBrush="Brown"
BorderThickness="1"
CornerRadius="4"
Padding="4"
Height="Auto">
<ItemsControl
HorizontalContentAlignment="Stretch">
<Expander
Header="Expander A"
IsExpanded="False">
<ItemsControl
HorizontalContentAlignment="Stretch">
<!-- TextView -->
<TextBlock>Content A</TextBlock>
<TextBlock>Content B</TextBlock>
</ItemsControl>
</Expander>
</ItemsControl>
</Border>
</ItemsControl>
</ScrollViewer>
我是用在边境双扩展器和双边框部分进行测试。
I was testing with double Expanders in the Border and double Border sections.