【发布时间】:2014-01-09 16:53:34
【问题描述】:
我有一个问题,当 TreeView 放置在具有 ScrollViewer 的容器中时,TreeView 的滚动条不起作用,而是调整了容器的 ScrollViewer 内容的大小,以便所有 TreeView 项目都可见。
在 WinForms 中我可以设置容器的最小内容宽度和高度,但是如何在 WPF 中实现呢?
以下是 XAML 示例:
<Window x:Class="TestWpfTreeViewInsideScrollViewer.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>
<ScrollViewer Name="scroll1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" >
<Grid MinHeight="230" MinWidth="200" Grid.IsSharedSizeScope="True">
<Button Content="Button" Width="74" Height="52" Margin="10,24,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Content="Button" Height="52" Margin="89,24,10,0" VerticalAlignment="Top"/>
<Button Content="Button" Width="74" Height="52" Margin="10,81,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TreeView Margin="10,138,10,55">
<TreeViewItem IsExpanded="True" Header="This is a long text but the treeview is not scrolling">
Instead the TreeView is expanding its size to fit all these nodes inside it, i want that the upper scroller take in only when grid minwidth 200 is reached, not before
<TreeViewItem IsExpanded="True" Header="This is a long text but the treeview is not scrolling">This is a long text but the treeview is not scrolling
</TreeViewItem>
</TreeViewItem>
<TreeViewItem IsExpanded="True" Header="This is a long text but the treeview is not scrolling">This is a long text but the treeview is not scrolling</TreeViewItem>
<TreeViewItem IsExpanded="True" Header="This is a long text but the treeview is not scrolling">This is a long text but the treeview is not scrolling</TreeViewItem>
</TreeView>
<Button Content="Button" Margin="10,0,10,10" Height="40" VerticalAlignment="Bottom"/>
</Grid>
</ScrollViewer>
</Grid>
【问题讨论】:
标签: wpf treeview scrollviewer