?
Solved

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

Posted on 2013-05-23
9
Medium Priority
?
357 Views
Last Modified: 2013-05-29
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

0
Comment
Question by:darbid73
  • 4
  • 4
9 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39190194
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.
0
 
LVL 35

Expert Comment

by:sarabande
ID: 39190355
you may look at the following article.

http://www.devcurry.com/2011/10/wpf-4-style-listbox-items-using.html

Sara
0
 
LVL 20

Author Comment

by:darbid73
ID: 39190451
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.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 35

Expert Comment

by:sarabande
ID: 39190489
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
0
 
LVL 20

Author Comment

by:darbid73
ID: 39190566
Does does the ItemContainerStyle effect the whole size or just the size of each item?
0
 
LVL 35

Expert Comment

by:sarabande
ID: 39190659
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
0
 
LVL 20

Accepted Solution

by:
darbid73 earned 0 total points
ID: 39194508
My original code is correct.  The issue I have is that the windows in which the autocompletebox is hosted is too small.

So this code is correct.

<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

0
 
LVL 20

Author Closing Comment

by:darbid73
ID: 39203932
Thanks guys but I got this one myself.
0
 
LVL 35

Expert Comment

by:sarabande
ID: 39204981
you made both the mistake and the solution yourself :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question