【问题标题】:WPF XAML treeview in a stack panel - no scrolling?堆栈面板中的 WPF XAML 树视图 - 没有滚动?
【发布时间】:2017-08-02 01:42:48
【问题描述】:

所以我的 XAML 中有一个 TreeView 控件。它工作正常。如果我将树视图扩展为大于它所在的用户控件,我会得到一个滚动条,这很好。但是,在这个用户控件中,我想要一些其他的东西。所以我将树视图与其他一些东西一起放在堆栈面板中,如果树视图扩展为大于它所在的用户控件,这一次我不会得到滚动条。

这是其他人遇到过的问题吗?有解决办法吗?

【问题讨论】:

标签: wpf xaml


【解决方案1】:

将您的堆栈面板嵌入到 ScrollViewer:stackoverflow.com/a/6250287/7517676。您可能还必须根据需要显式设置 VerticalScrollBarVisibility 和 Horizo​​ntalScrollBarVisibility。 这是一个代码示例:

<ScrollViewer VerticalScrollBarVisibility="Auto">
  <StackPanel ... />
</ScrollViewer>

【讨论】:

  • 我确实有一个滚动条,但鼠标滚动(仍然)被禁用
【解决方案2】:

基于this answer,StackPanel 不是 TreeView 的正确容器,但 Grid 是。所以这将允许通过鼠标和滚动条在 TreeView 内滚动:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="30"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Label>Some descriptive label.</Label>
    <TreeView Grid.Row="1" ItemsSource="{Binding SomeSource, Mode=OneWay}">
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate DataType="{x:Type local:MyNodeType}" ItemsSource="{Binding Children}">
                <Label Content="{Binding NodeName}"/>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>
</Grid>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多