Click here to Skip to main content
13,046,184 members (86,245 online)
Rate this:
Please Sign up or sign in to vote.
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:

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 10-May-13 5:19am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100