Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XAML WPF User-controls
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 6:19am
Pheonyx11.8K

1 solution

Rate this: bad
good
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:
http://stackoverflow.com/questions/4521508/prevent-wpf-control-from-expanding-beyond-viewable-area[^]
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 381
1 Praneet Nadkar 237
2 Marcin Kozub 225
3 Sergey Alexandrovich Kryukov 200
4 Shweta N Mishra 161
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
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