0
如何在佔據窗口左角的窗口上呈現可滾動的wpf樹視圖控件,並使用窗口高度進行調整。我一直在嘗試使用Grid和dockpanel,但除非指定高度,否則不會出現滾動條。請用XAML標記回答。如何在wpf表單上顯示可滾動的treeview控件
如何在佔據窗口左角的窗口上呈現可滾動的wpf樹視圖控件,並使用窗口高度進行調整。我一直在嘗試使用Grid和dockpanel,但除非指定高度,否則不會出現滾動條。請用XAML標記回答。如何在wpf表單上顯示可滾動的treeview控件
告訴我,如果這是你需要什麼:
<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如何啓用。
我該如何製作樹視圖控件才能填滿屏幕的高度。 – TrustyCoder
上面的示例使樹視圖獲取所有可用的垂直空間 - 所有窗口高度。如果您希望窗口占用所有的屏幕空間,請爲窗口屬性設置WindowState =「最大化」。 –