2012-11-09 77 views

回答

1

告訴我,如果這是你需要什麼:

<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> 

假的ItemSource:

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 }; 

因此,關鍵的是,滾動條將出現只有當ScrollViewer中的含量都比較大可用尺寸。通過在TreeView屬性中指定ScrollViewer.VerticalScrollBarVisibility="Visible",滾動查看器將始終存在(啓用或禁用)。嘗試更改窗口的高度以查看ScrolBar如何啓用。

+0

我該如何製作樹視圖控件才能填滿屏幕的高度。 – TrustyCoder

+0

上面的示例使樹視圖獲取所有可用的垂直空間 - 所有窗口高度。如果您希望窗口占用所有的屏幕空間,請爲窗口屬性設置WindowState =「最大化」。 –