I would like my TreeView to stay within the availabe space within the window. By default the height grows as large as ncessary exceeding the window height. I can set MaxHeight to make it fit, but this wont be adjusted if the window gets taller.
How can I make the height adjust to window size but not exceed it?
Yazhini MPPosted Dec 11, 2021, 4:40 AM
My reference is,
To set the MaxHeight attribute of the treeview control in relation to the size of the window it was hosted in When the MaxHeight is surpassed, we also require the scrollbar to appear.
I added the event to the XAML window tag.
SizeChanged="Window SizeChanged"
Then, in the code-behind, I implemented an event to set the treeview's MaxHeight relative to the window's ActualHeight. I utilised an 85 percent ratio. The tree view will be 85 percent of the window's height.
Window SizeChanged is a private void (object sender, SizeChangedEventArgs e)
treeView1.MaxHeight = actualHieght *.85; double actualHieght = NameOfTheWindow.ActualHeight;
All of the prerequisites have been met. When the contents of the treeview surpass the MaxHeight, the treeview grows in size relative to the window, and the vertical scrollbar appears.
Srinivasan RamamoorthiPosted Dec 9, 2021, 4:28 AM