VerticalAlignment=“拉伸”从我的容器中伸出

发布于 2024-12-10 09:21:56 字数 741 浏览 0 评论 0原文

我有一个父容器,用于保存所有用户控件。问题是我使用 VerticalAlignment="Stretch" 将内容拉伸到完整高度并获得垂直滚动条,用户控件被拉伸太多。出现垂直滚动条但无法滚动。我知道这一点是因为滚动条的向下箭头不可见。

我有 ,可以在其中分配各种控件。例如,下面的 XAML 在拉伸方面不起作用。

<StackPanel>
    <TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" Margin="0 0 0 8" />
    <ScrollViewer VerticalAlignment="Stretch">
        <TreeView 
        ItemsSource="{Binding Listing}"
        Grid.Row="1" 
        BorderThickness="0" 
        VirtualizingStackPanel.IsVirtualizing="True" />
    </ScrollViewer>
</StackPanel>

我只想让 TreeView 拉伸并显示垂直滚动条。

有什么想法吗?

I have a parent container that is used to hold all of my user controls. The issue is that I use VerticalAlignment="Stretch" to stretch contents to the full height and get a vertical scroll bar the user control gets stretched too much. The vertical scrollbar appears but there is no way to scroll. I know this because the down arrow for the scroll bar isn't visible.

I have <ContentControl Content="{Binding Workspace}" /> which is where a variety of controls can be assigned. For example, here is the XAML that is not working property in regards to stretching.

<StackPanel>
    <TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" Margin="0 0 0 8" />
    <ScrollViewer VerticalAlignment="Stretch">
        <TreeView 
        ItemsSource="{Binding Listing}"
        Grid.Row="1" 
        BorderThickness="0" 
        VirtualizingStackPanel.IsVirtualizing="True" />
    </ScrollViewer>
</StackPanel>

I only want to the TreeView to stretch and display a vertical scrollbar.

Any ideas?

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

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

发布评论

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

评论(1

ゞ记忆︶ㄣ 2024-12-17 09:21:56

我怀疑 StackPanel 的高度不受限制,因此它会增长以容纳 ScrollViewer。您可以通过在 StackPanel 上添加边框来检查这一点。

    <Border>
        <StackPanel>   
            <TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" />   
            <ScrollViewer VerticalAlignment="Stretch">   
                <TreeView ItemsSource="{Binding Listing}"  BorderThickness="0"    
                VirtualizingStackPanel.IsVirtualizing="True" />   
            </ScrollViewer>   
        </StackPanel>          
    </Border>

I suspect the height of the StackPanel is not contrained so it grows to accomodate the ScrollViewer. You can check this by putting a border on the StackPanel.

    <Border>
        <StackPanel>   
            <TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" />   
            <ScrollViewer VerticalAlignment="Stretch">   
                <TreeView ItemsSource="{Binding Listing}"  BorderThickness="0"    
                VirtualizingStackPanel.IsVirtualizing="True" />   
            </ScrollViewer>   
        </StackPanel>          
    </Border>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文