wpf中的树视图大小

时间:2012-06-16 08:55:09

标签: c# wpf treeview scrollbar

请告诉我如何更改屏幕分辨率时如何重新调整树形视图控制的高度?

请看这段代码:

<TreeView  Name="treeView1" Height="150" VerticalAlignment="Top">
    <TreeViewItem Header="Root" IsExpanded="True">
        <TreeViewItem Header="Item 1"></TreeViewItem>
        <TreeViewItem Header="Item 2"></TreeViewItem>
        <TreeViewItem Header="Item 3"></TreeViewItem>
        <TreeViewItem Header="Item 4"></TreeViewItem>
        <TreeViewItem Header="Item 5"></TreeViewItem>
        <TreeViewItem Header="Item 6"></TreeViewItem>
        <TreeViewItem Header="Item 7"></TreeViewItem>
        <TreeViewItem Header="Item 8"></TreeViewItem>
        <TreeViewItem Header="Item 9"></TreeViewItem>
        <TreeViewItem Header="Item 10"></TreeViewItem>
        <TreeViewItem Header="Item 11"></TreeViewItem>
        <TreeViewItem Header="Item 12"></TreeViewItem>
        <TreeViewItem Header="Item 13"></TreeViewItem>
        <TreeViewItem Header="Item 14"></TreeViewItem>
        <TreeViewItem Header="Item 15"></TreeViewItem>
        <TreeViewItem Header="Item 16"></TreeViewItem>
        <TreeViewItem Header="Item 17"></TreeViewItem>
        <TreeViewItem Header="Item 18"></TreeViewItem>
        <TreeViewItem Header="Item 19"></TreeViewItem>
        <TreeViewItem Header="Item 20"></TreeViewItem>
        <TreeViewItem Header="Item 21"></TreeViewItem>
        <TreeViewItem Header="Item 22"></TreeViewItem>
        <TreeViewItem Header="Item 23"></TreeViewItem>
        <TreeViewItem Header="Item 24"></TreeViewItem>
        <TreeViewItem Header="Item 24"></TreeViewItem>
    </TreeViewItem>
</TreeView>

在一些屏幕分辨率中,我可以看到所有的点头,在某些分辨率中,我看到一个滚动条。 我想看到没有滚动条的所有节点。

1 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情,使用SystemEvents.DisplaySettingsChanged事件:

public partial class Window1 : Window
{
    public static EventHandler HandleDisplaySettingsChanged = 
        new EventHandler(SystemEvents_DisplaySettingsChanged);

    public Window1()
    {
        InitializeComponent();
        Microsoft.Win32.SystemEvents.DisplaySettingsChanged += HandleDisplaySettingsChanged;
    }

    public void Close()
    {
        SystemEvents.DisplaySettingsChanged -= HandleDisplaySettingsChanged;
    }

    public static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
    {
        Console.WriteLine("display settings changed");

        // change treeview size as you think what is appropriate here...
    }
}