0

我在列表框中有扩展器。如果我现在将 ListView 放入最后一个 Expander,则 ListView 的大小正好可以显示所有项目。到目前为止,这就是我想要的。但现在不可能将 ListBox 向下滚动到 ListView 的末尾。

为了允许用户将 ListBox 向下滚动到最后一项的末尾,即 ListView 的末尾,我需要做什么?

这是我的简化代码:

<Window x:Class="ExpanderTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ListBox HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled">

        <Expander Header="text">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="100"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0">some text</Label>
                <Label Grid.Column="1">some text</Label>
            </Grid>
        </Expander>

        <Expander Header="Buttons">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Button Grid.Row="0">Button1</Button>
                <StackPanel Grid.Row="1" Orientation="Horizontal">
                    <Button>Button2</Button>
                    <Button>Button3</Button>
                    <Button>Button4</Button>
                    <Button>Button5</Button>
                </StackPanel>
            </Grid>
        </Expander>

        <Expander Header="Much Information" IsExpanded="True">
            <ListView>
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn Header="Variable" Width="160" />
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
                <ListViewItem>Line 0</ListViewItem>
                <ListViewItem>Line 1</ListViewItem>
                <ListViewItem>Line 2</ListViewItem>
                <ListViewItem>Line 3</ListViewItem>
                <ListViewItem>Line 4</ListViewItem>
                <ListViewItem>Line 5</ListViewItem>
                <ListViewItem>Line 6</ListViewItem>
                <ListViewItem>Line 7</ListViewItem>
                <ListViewItem>Line 8</ListViewItem>
                <ListViewItem>Line 9</ListViewItem>
                <ListViewItem>Line 10</ListViewItem>
                <ListViewItem>Line 11</ListViewItem>
                <ListViewItem>Line 12</ListViewItem>
                <ListViewItem>Line 13</ListViewItem>
                <ListViewItem>Line 14</ListViewItem>
                <ListViewItem>Line 15</ListViewItem>
                <ListViewItem>Line 16</ListViewItem>
                <ListViewItem>Line 17</ListViewItem>
                <ListViewItem>Line 18</ListViewItem>
                <ListViewItem>Line 19</ListViewItem>
                <ListViewItem>Line 20</ListViewItem>
                <ListViewItem>Line 21</ListViewItem>
                <ListViewItem>Line 22</ListViewItem>
                <ListViewItem>Line 23</ListViewItem>
                <ListViewItem>Line 24</ListViewItem>
                <ListViewItem>Line 25</ListViewItem>
                <ListViewItem>Line 26</ListViewItem>
                <ListViewItem>Line 27</ListViewItem>
                <ListViewItem>Line 28</ListViewItem>
                <ListViewItem>Line 29</ListViewItem>
                <ListViewItem>Line 30</ListViewItem>
                <ListViewItem>Line 31</ListViewItem>
                <ListViewItem>Line 32</ListViewItem>
                <ListViewItem>Line 33</ListViewItem>
                <ListViewItem>Line 34</ListViewItem>
                <ListViewItem>Line 35</ListViewItem>
                <ListViewItem>Line 36</ListViewItem>
                <ListViewItem>Line 37</ListViewItem>
                <ListViewItem>Line 38</ListViewItem>
                <ListViewItem>Line 39</ListViewItem>
            </ListView>
        </Expander>
    </ListBox>
</Grid>

4

1 回答 1

1

一种解决方案是将扩展器放入 ScrollViewer 内的 StackPanel 中,而不是使用 ListBox。

如果您需要保留外部 ListBox,您可以禁用其上的 ScrollViewer,并将该 ListBox 包装在 ScrollViewer 中。

<Grid>
    <ScrollViewer>
        <StackPanel>

            <Expander Header="text">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="100"/>
                    </Grid.ColumnDefinitions>
                    <Label Grid.Column="0">some text</Label>
                    <Label Grid.Column="1">some text</Label>
                </Grid>
            </Expander>

            <Expander Header="Buttons">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Button Grid.Row="0">Button1</Button>
                    <StackPanel Grid.Row="1" Orientation="Horizontal">
                        <Button>Button2</Button>
                        <Button>Button3</Button>
                        <Button>Button4</Button>
                        <Button>Button5</Button>
                    </StackPanel>
                </Grid>
            </Expander>

            <Expander Header="Much Information" IsExpanded="True">
                <ListView>
                    <ListView.View>
                        <GridView>
                            <GridView.Columns>
                                <GridViewColumn Header="Variable" Width="160" />
                            </GridView.Columns>
                        </GridView>
                    </ListView.View>
                    <ListViewItem>Line 0</ListViewItem>
                    <ListViewItem>Line 1</ListViewItem>
                    <ListViewItem>Line 2</ListViewItem>
                    <ListViewItem>Line 3</ListViewItem>
                    <ListViewItem>Line 4</ListViewItem>
                    <ListViewItem>Line 5</ListViewItem>
                    <ListViewItem>Line 6</ListViewItem>
                    <ListViewItem>Line 7</ListViewItem>
                    <ListViewItem>Line 8</ListViewItem>
                    <ListViewItem>Line 9</ListViewItem>
                    <ListViewItem>Line 10</ListViewItem>
                    <ListViewItem>Line 11</ListViewItem>
                    <ListViewItem>Line 12</ListViewItem>
                    <ListViewItem>Line 13</ListViewItem>
                    <ListViewItem>Line 14</ListViewItem>
                    <ListViewItem>Line 15</ListViewItem>
                    <ListViewItem>Line 16</ListViewItem>
                    <ListViewItem>Line 17</ListViewItem>
                    <ListViewItem>Line 18</ListViewItem>
                    <ListViewItem>Line 19</ListViewItem>
                    <ListViewItem>Line 20</ListViewItem>
                    <ListViewItem>Line 21</ListViewItem>
                    <ListViewItem>Line 22</ListViewItem>
                    <ListViewItem>Line 23</ListViewItem>
                    <ListViewItem>Line 24</ListViewItem>
                    <ListViewItem>Line 25</ListViewItem>
                    <ListViewItem>Line 26</ListViewItem>
                    <ListViewItem>Line 27</ListViewItem>
                    <ListViewItem>Line 28</ListViewItem>
                    <ListViewItem>Line 29</ListViewItem>
                    <ListViewItem>Line 30</ListViewItem>
                    <ListViewItem>Line 31</ListViewItem>
                    <ListViewItem>Line 32</ListViewItem>
                    <ListViewItem>Line 33</ListViewItem>
                    <ListViewItem>Line 34</ListViewItem>
                    <ListViewItem>Line 35</ListViewItem>
                    <ListViewItem>Line 36</ListViewItem>
                    <ListViewItem>Line 37</ListViewItem>
                    <ListViewItem>Line 38</ListViewItem>
                    <ListViewItem>Line 39</ListViewItem>
                </ListView>
            </Expander>
        </StackPanel>
    </ScrollViewer>
</Grid>
于 2013-01-07T20:10:21.633 回答