Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

I have an issue that I don't know how to resolve.
I am building a WPF C# application using a MVVM approach (well trying).

I have a container window that has a menu on the left hand side, on the right different views are loaded depending on which menu option is selected.

However, when I load a view that has a list box in it and the code behind starts adding items to the listbox's data source the listbox grows beyond the visible window. As a result it does not enable the scroll bar and the bottom entries cannot be seen.

My question is how can I ensure that my usercontrol, and in turn it's list box does not grow beyond the visible window of its container.

I tried putting the following in the user control Xaml but it has had no effect:

XML
MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ContentControl, AncestorLevel=1}, Path=Height}"


Any ideas what I could try because I would have thought this would bind the user controls MaxHeight to the size of the containing control (i.e. the cell in a grid where it is located)?
Posted

1 solution

Ahh, I found my issue.

It was actually further down in my user control.
For those that are interested I was using stackpanel to contain my listbox.
As the listbox grew so did the stackpanel (which is how it is meant to behave). However the stackpanel does not stop growing when it reaches the user controls height, instead it continues.
I replaced my stackpanel with a grid and hey presto it started to work!

Source of this information was here:
http://stackoverflow.com/questions/4521508/prevent-wpf-control-from-expanding-beyond-viewable-area[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900