Click here to Skip to main content
15,559,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two WP Grid controls next to each other. One has a fixed set of fields. The other is bound to a list. I want the two Grid controls to be the same height.

The code I have now does this 'by accident' but it makes both Grid controls as long as the Grid containing the list of items. I want the opposite. I want the Grid with the list to be locked at the same size as the other Grid and for WPF to automatically put scrollbars on the list to view items which go off the bottom of the list.

Hope this makes sense.

Kind wishes ~ Patrick

What I have tried:

I have tried using the Grid.IsSharedSizeScope="True" on the container for both Grid controls and then in each Grid, setting <RowDefinition SharedSizeGroup="xxxx"/> in each Grid.

This keeps both Grid controls the same size but unfortunately simply does what I had before - both Grid controls grow to accommodate all the items in the list.
Updated 24-Aug-16 13:06pm

1 solution

Grid size is bounded by the size of their container, so your problem means there's at least one parent in the visual tree of the Grid that allows unbounded growth. For example, since a StackPanel has unbounded growth if a Grid is the child of a StackPanel there is unbounded growth of the Grid as well. You can either change the visual tree to fix the offending element, or you will have to set/manipulate the height of the Grid/containers manually.
Share this answer
Patrick Skelton 25-Aug-16 3:36am    
Higher up the tree, I have DockPanel, Border and other instances of Grid. Your explanation is one of the clearest and most concise I have read on WPF layout, and hence the 'Accept Answer' and 5-stars because I am sure it will lead to a solution when I get time to play with it. Thank you.
PureNsanity 25-Aug-16 8:27am    
DockPanel, Border, and Grid are all bounded so those won't be it. If you're using VS 2015 it has a visual tree inspector built into the debugger, but if you're using previous versions tools like WPF Inspector can help readily identify the offending object. StackPanel is probably one of the most common ones, but another that could be counter-intuitive is the ScrollViewer. A ScrollViewer is actually unbounded... If you're looking up the visual tree and you're not sure which control is or isn't, one easy way to test is by setting the height of the containers to a fixed value going up the tree. Set the value as a fixed value, test, and move up the tree. Whenever you move up and it goes from fixed height to unbounded growth, you know a container underneath it is an offending container. You may have to go through this process multiple times up to the root window.
Patrick Skelton 25-Aug-16 12:19pm    
Thanks for the tips. I'll have a poke about. I am a bit worried though because I'm pretty sure I only have the controls I have mentioned. I must be mistaken.

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