Solved

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

Posted on 2013-05-23
9
341 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 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
How our DevOps Teams Maximize Uptime

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

 
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
 
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 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 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 33

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 76
c# - Best approach for objects in functions 3 24
Name Space error VS2015 1 22
Code enhancement 4 20
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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