WPF 列表框不受窗口限制

发布于 2024-09-06 01:24:34 字数 1499 浏览 2 评论 0原文

我正在开发一个复杂的应用程序,并且遇到列表框不受窗口高度限制的问题。这是它的简化版本。我怎样才能让这个列表框正确地受到窗口的限制?现在,底部滚动按钮位于屏幕之外,直到窗口足够大以容纳整个列表框之前才能看到。我需要找到一个使列表框始终有界的解决方案,因为我必须通过 ScaleTransform 实现缩放。

<Grid>        
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
        <Grid Name="stack">
            <Grid.LayoutTransform>
                <ScaleTransform
                 ScaleX="{Binding ElementName=slider, Path=Value}" 
                 ScaleY="{Binding ElementName=slider, Path=Value}" />
            </Grid.LayoutTransform>
            <WrapPanel HorizontalAlignment="Left">
                <Expander IsExpanded="False" Width="300">hey</Expander>
                <Expander IsExpanded="True"  VerticalAlignment="Stretch" ClipToBounds="True">
                    <Grid>                            
                        <ListBox >                            
                            <Button>hey</Button>
                            <!-- just add a lot more of these to see the problem -->
                            <Button>hey</Button>
                         </ListBox>
                    </Grid>
                </Expander>
            </WrapPanel>

        </Grid>
    <Slider Grid.Column="1" Name="slider" Minimum="1" Maximum="4" Value="1" />

</Grid>

I'm working on a complex application, and I'm having an issue with a listbox not being bounded by the window height. Here's a simplified version of what it looks like. How would I get this listbox to correctly be bounded by the window? Right now, the bottom scroll button is off the screen and cannot be seen until the window is big enough to fit the entire listbox. I need to find a solution that makes the listbox always bounded because I have to implement zooming via a ScaleTransform.

<Grid>        
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
        <Grid Name="stack">
            <Grid.LayoutTransform>
                <ScaleTransform
                 ScaleX="{Binding ElementName=slider, Path=Value}" 
                 ScaleY="{Binding ElementName=slider, Path=Value}" />
            </Grid.LayoutTransform>
            <WrapPanel HorizontalAlignment="Left">
                <Expander IsExpanded="False" Width="300">hey</Expander>
                <Expander IsExpanded="True"  VerticalAlignment="Stretch" ClipToBounds="True">
                    <Grid>                            
                        <ListBox >                            
                            <Button>hey</Button>
                            <!-- just add a lot more of these to see the problem -->
                            <Button>hey</Button>
                         </ListBox>
                    </Grid>
                </Expander>
            </WrapPanel>

        </Grid>
    <Slider Grid.Column="1" Name="slider" Minimum="1" Maximum="4" Value="1" />

</Grid>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

佞臣 2024-09-13 01:24:34

尝试以下代码:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Border Grid.Row="0">
        <Grid Name="stack">
            <Grid.LayoutTransform>
                <ScaleTransform ScaleX="{Binding ElementName=slider, Path=Value}"
                                ScaleY="{Binding ElementName=slider, Path=Value}" />
            </Grid.LayoutTransform>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Border Grid.Row="0">
                    <Expander IsExpanded="False"
                              Width="300">hey</Expander>
                </Border>
                <Border Grid.Row="1">
                    <Expander IsExpanded="True"
                              VerticalAlignment="Stretch"
                              ClipToBounds="True">
                        <Grid>
                            <ListBox>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <!-- just add a lot more of these to see the problem -->
                                <Button>hey</Button>
                            </ListBox>
                        </Grid>
                    </Expander>
                </Border>
            </Grid>
        </Grid>
    </Border>
    <Border Grid.Row="1">
        <Slider Name="slider"
                Minimum="1"
                Maximum="4"
                Value="1" />
    </Border>
</Grid>

try the following code:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Border Grid.Row="0">
        <Grid Name="stack">
            <Grid.LayoutTransform>
                <ScaleTransform ScaleX="{Binding ElementName=slider, Path=Value}"
                                ScaleY="{Binding ElementName=slider, Path=Value}" />
            </Grid.LayoutTransform>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Border Grid.Row="0">
                    <Expander IsExpanded="False"
                              Width="300">hey</Expander>
                </Border>
                <Border Grid.Row="1">
                    <Expander IsExpanded="True"
                              VerticalAlignment="Stretch"
                              ClipToBounds="True">
                        <Grid>
                            <ListBox>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <Button>hey</Button>
                                <!-- just add a lot more of these to see the problem -->
                                <Button>hey</Button>
                            </ListBox>
                        </Grid>
                    </Expander>
                </Border>
            </Grid>
        </Grid>
    </Border>
    <Border Grid.Row="1">
        <Slider Name="slider"
                Minimum="1"
                Maximum="4"
                Value="1" />
    </Border>
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文