Solved

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

Posted on 2013-05-23
9
335 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 44

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 32

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 19

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
 
LVL 32

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 19

Author Comment

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

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 19

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 19

Author Closing Comment

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

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now