Nested Scroll Areas

前端 未结 7 575
失恋的感觉
失恋的感觉 2020-12-05 15:34

I creating a control for WPF, and I have a question for you WPF gurus out there.

I want my control to be able to expand to fit a resizable window.

In my con

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 16:14

    Create a method in the code-behind that sets the ListBox's MaxHeight to the height of whatever control is containing it and other controls. If the Listbox has any controls/margins/padding above or below it, subtract their heights from the container height assigned to MaxHeight. Call this method in the main windows "loaded" and "window resize" event handlers.

    This should give you the best of both worlds. You are giving the ListBox a "fixed" size that will cause it to scroll in spite of the fact that the main window has its own scrollbar.

提交回复
热议问题