Link to home
Start Free TrialLog in
Avatar of darbid73
darbid73Flag for Germany

asked on

How to set the height of a ListBox which is contained within another control.

I am using the autocompletebox from the wpftoolkit which I understand has a list box as part of the control.  This list box is on a popup.  I have thrown a height at everything and the only thing I can get to happen is the container of popup changes height, but the individual items remain contained in some height I cannot change.

<Popup x:Name="Popup" Height="500" >
                            <Grid Background="{TemplateBinding Background}" Opacity="{TemplateBinding Opacity}" Height="500">
                                <Border x:Name="PopupBorder" BorderThickness="0" Background="{DynamicResource SCB_TextBackgroundNoFocus}" HorizontalAlignment="Stretch" Height="500">
									<!--Removed a Border from the template here-->

                                    <ListBox   x:Name="Selector" Style="{DynamicResource ListBoxStyle2}" Height="500" BorderThickness="0" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemTemplate="{TemplateBinding ItemTemplate}" ItemContainerStyle="{TemplateBinding ItemContainerStyle}" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
									
								</Border>
							</Grid>
						</Popup>

Open in new window

Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Typically the height of items in a listbox is controlled automatically and related to the font you use.
I don't know this particular control but usually to get what you want requires you use owner drawing - and draw everything yourself.
Avatar of darbid73

ASKER

Andy I thought the "height of items" in a listbox would be controlled by the item template.  The overall height of the listbox in my opinion should be another thing.

sarabande I am not sure how that helps me, maybe you could suggest how that helps me.

As it currently is the popup or contain is changing size.  Within this is an area which is the list box which is staying at a fixed size.  If there are more items than fit in this "fixed size" they are just not being displayed. I can for example use the arrow key to go down and it will go down past the fixed size to other items, so they are there it is just the list box has some size fixed to it.
The ItemContainerStyle provides a mechanism for applying styles formatting on individual WPF ListBox items.

i read this sentence and hoped that could help you for your task.

in the sample there are "Margin" and "Padding" properties for <Setters> which seem to have influence on item layout.

Typically the height of items in a listbox is controlled automatically and related to the font you use.

if a listbox was defined by resources the only height to specify is the total height.

Sara
Does does the ItemContainerStyle effect the whole size or just the size of each item?
as far as i could deduce from the images the setters properties effect all items of the listbox.

the 'Margin" and "Padding" seem to make the left and top offset of each item. i found another sample where the margin value was "0, 4, 0, 0". that means you could specify margins for all directions.

in the following sample at
http://www.dotnetspider.com/resources/34567-Using-ItemContainerStyle-ListView.aspx

they used

<Grid.RowDefinitions>                                        
    <RowDefinition Height="Auto"></RowDefinition>                                        
    <RowDefinition Height="Auto"></RowDefinition>

Open in new window

below <Setters>.

i wonder why the height definition was duplicated but probably the height property of rowdefinition is that you were looking for.

Sara
ASKER CERTIFIED SOLUTION
Avatar of darbid73
darbid73
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys but I got this one myself.
you made both the mistake and the solution yourself :-)