Solved

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

Posted on 2013-05-23
9
338 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 33

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 33

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 33

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 33

Expert Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 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

15 Experts available now in Live!

Get 1:1 Help Now