I am working on a WPF application and using a scrollViewer to view the content that is offlimit the screen area. Working fine, no issues.
But if my window contains a Listbox or Grid or anything like that and that control has many records then instead of adding a scrollbar to itself, it just increase the height of the control and window itself because scrollviewer believes it needs to extend.
I don’t want to hardcode the listbox’s height, because that make it same in different resolutions, i want to make it increase its height but not always as scrollviewer make it do so.
Thanks
You can’t include a variable height/width object inside a
ScrollViewerwithout setting the height/width of the viewer.The scroll viewer effectively has infinite height so the grid expands to fill the “available” space – hence the effect you are seeing. As @JoeWhite says in his comments, the
ScrollVieweris a container that can be as tall as it needs to be to hold all of its content. Anchoring wouldn’t help – in effect, yourListBoxalready is anchored, it’s just anchored to something that says “oh, I’ll be whatever size you need me to be”.You’ll need to either restrict the height, move the
ListBoxoutside theScrollVieweror use something other than aScrollViewer.Again quoting @Joe “These are the hazards of putting a scrolling area inside another scrolling area – it’s poor usability and it’s hard to define the behaviour.”