如何在wpf窗体上显示可滚动的treeview控件
如何在占据窗口左角并随窗口高度调整的窗口上呈现可滚动的wpf treeview控件。我一直在试验Grid和dockpanel,但除非指定高度,否则不会显示滚动条。请用XAML标记回答。告诉我这是否是您需要的:如何在wpf窗体上显示可滚动的treeview控件,wpf,treeview,scroll,Wpf,Treeview,Scroll,如何在占据窗口左角并随窗口高度调整的窗口上呈现可滚动的wpf treeview控件。我一直在试验Grid和dockpanel,但除非指定高度,否则不会显示滚动条。请用XAML标记回答。告诉我这是否是您需要的: <Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Name="window" Height="350" Width="525">
<Grid>
<TreeView
ItemsSource="{Binding ElementName=window, Path=TreeviewDummySource}"
Background="Gray"
Width="150"
HorizontalAlignment="Left"
ScrollViewer.VerticalScrollBarVisibility="Visible"/>
</Grid>
</Window>
因此,诀窍在于,只有当ScrollViewer的内容大于可用大小时,滚动条才会出现。通过在TreeView属性中指定ScrollViewer.VerticalScrollBarVisibility=“Visible”,ScrollViewer将始终存在(启用或禁用)。尝试更改窗口的高度以查看ScrolBar是如何启用的。如何使treeview控件填充屏幕的高度。上面的示例使树视图占据所有可用的垂直空间-所有窗口高度。如果希望窗口占用所有屏幕空间,请为窗口属性设置WindowState=“Maximized”。
public int[] TreeviewDummySource
{
get { return treeviewDummySource; }
}
private int[] treeviewDummySource = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };