带有嵌套扩展器的 ListView 不会折叠

发布于 2024-08-13 03:13:03 字数 1699 浏览 9 评论 0原文

这个问题与其他相同未回答的问题

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>-->

我在 ItemsControlStackPanel 中有 ParameterGroupView,因为实际上有很多 ParameterGroupView条目。交换到 StackPanel 不会改变行为。

删除 Boarder 不会影响行为,但拥有它有助于仅使用单个 ParameterGroupView 显示行为。

外部 ListView 中可以有许多 Expander 部分,并且 Expander 内部 ListView 内部可以有许多实体。

外部的ListViewExpander将取代TreeView,它用于具有可折叠节点的列表,但是TreeView< /em> 网格的内部使用,意味着 TextView 项目被水平压缩,就像删除以太 Horizo​​ntalContentAlignment="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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕嗳→ 2024-08-20 03:13:03

找到了解决方案,它详细说明了问题所在的位置。

ItemControl 接受 ItemsSource 并自动调整大小。因此,用 ItemControl 替换两个 ListView 会导致嵌套折叠。

但没有滚动,因此用 ScrollViewer 包裹外部 ItemControl,可以再现完整的所需效果。

<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>

我正在边框和双边框部分中使用双扩展器进行测试。

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.

<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.

美人迟暮 2024-08-20 03:13:03

这里要做的最明显的事情是将扩展器放在列表视图之外的容器中:

<Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4">
    <StackPanel>

        <Expander Header="Expander A" IsExpanded="False">
            <ListView HorizontalContentAlignment="Stretch" MinWidth="100">
                <ListBox Name="listb"></ListBox>

                <!-- TextView -->
                <TextBlock >Content A</TextBlock>
                <TextBlock>Content B</TextBlock>

            </ListView>
        </Expander>
    </StackPanel>
</Border>

容器围绕内容调整大小就可以了。

如果你绝对必须将它放在 ListView 中(这是可能的),那么我不知道有什么方法可以让 ListView 在增长后轻松调整大小(除了设置整个事物的显式大小之外,这是笨拙且无用的) 。如果是这种情况,那么如果您希望能够看到它,您可能必须使用可控列表框来显示所有打开的扩展器,或者以不同的方式显示内容(例如在弹出窗口中,也许?)一目了然。

The most obvious thing to do here is to put the expanders in a container other than a listview:

<Border BorderBrush="Brown" BorderThickness="1" CornerRadius="4" Padding="4">
    <StackPanel>

        <Expander Header="Expander A" IsExpanded="False">
            <ListView HorizontalContentAlignment="Stretch" MinWidth="100">
                <ListBox Name="listb"></ListBox>

                <!-- TextView -->
                <TextBlock >Content A</TextBlock>
                <TextBlock>Content B</TextBlock>

            </ListView>
        </Expander>
    </StackPanel>
</Border>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文