0

请让我知道如何在更改屏幕分辨率时重新调整树视图控件的高度?

请看这段代码:

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

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

4

1 回答 1

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...
    }
}
于 2012-06-16T09:02:59.380 回答