简体   繁体   English

在WPF中的子控件上使用滚动条

[英]Use scroll bars on child controls in wpf

I have an explorer type window that I am trying to display in WPF. 我有一个尝试在WPF中显示的资源管理器类型窗口。

<Grid ScrollViewer.VerticalScrollBarVisibility="Disabled">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="350" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <telerik:RadTreeView Grid.Column="0" Name="ExplorerTree"
                        ScrollViewer.VerticalScrollBarVisibility="Visible"/>
    <GridSplitter Grid.Column="1" Grid.Row="1" Width="1" Grid.RowSpan="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
    <telerik:RadListBox Grid.Column="2" Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Visible" />
</Grid>

However, when I expand an object within the tree view, the scroll bar appears on the grid causing the entire window to scroll rather than just the contents of the tree view. 但是,当我在树视图中展开一个对象时,滚动条出现在网格上,导致整个窗口滚动,而不仅仅是树视图的内容。 What do I need to change to make the contents of the tree view scroll instead? 我需要更改什么才能使树形视图的内容滚动? I don't want to set it to a specific height as I would like the height of the tree view to adjust with the height of the parent in which it is displayed. 我不想将其设置为特定的高度,因为我希望树形视图的高度能够根据显示它的父级的高度进行调整。

If you just stop trying to set ScrollViewer properties altogether you should get the desired result as both RadTreeView and RadListBox will display a ScrollViewer automatically as needed (unless you have something else in the rest of your XAML that interferes with their normal behavior). 如果您只是停止尝试完全设置ScrollViewer属性,那么您应该会获得所需的结果,因为RadTreeView和RadListBox都将根据需要自动显示ScrollViewer(除非XAML的其余部分中有其他东西会干扰它们的正常行为)。 I used both these controls extensively without setting any ScrollViewer properties in XAML and that's what they do automatically although you might have to set their VerticalAlignment to stretch... not sure about that. 我广泛使用了这两个控件,而没有在XAML中设置任何ScrollViewer属性,这是它们自动执行的操作,尽管您可能必须将其VerticalAlignment设置为可拉伸...对此不确定。

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="350" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition />
  </Grid.ColumnDefinitions>
  <telerik:RadTreeView Grid.Column="0" Name="ExplorerTree"
    VerticalAlignment="Stretch"/>
  <GridSplitter Grid.Column="1" Grid.Row="1" Width="1" Grid.RowSpan="1"
    HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
  <telerik:RadListBox Grid.Column="2" Grid.Row="1" VerticalAlignment="Stretch" />
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM