views:

17

answers:

3

Space between items is to much. how can I lessen it?

A: 

Others out there may know better than me, but I would override the data template for the list box. For each individual item, explicitly specify the size of the text control.

For instance:

<ListBox Width="400" Margin="10" ItemsSource="{Binding Path=MyDataItems}">
   <ListBox.ItemTemplate>
     <DataTemplate>
       <TextBlock Text="{Binding Path=TaskName}" Height="27" />
     </DataTemplate>
   </ListBox.ItemTemplate>
 </ListBox>

It is definitely a little bit more work, but I'm not sure there is much else you can do for a list box.

j0rd4n
+1  A: 

Set the ItemContainerStyle to set the Margin and Padding as needed. Blend will help with this retemplating.

You can then also consider setting the DataTemplate.

Jeff Wilcox
A: 

ok i dont know really what u want, i am just having a guess that u want to lessen the space between the listboxitems present in your list box , then you can do it with a help of margin :

<Style x:Key="LedgerListBoxItem" TargetType="ListBoxItem">
        <Setter Property="Padding" Value="3"/>
        <Setter Property="Height" Value="24"/>
        <Setter Property="Width" Value="330"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="TabNavigation" Value="Local"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Grid Background="{TemplateBinding Background}">                      
                        <Grid HorizontalAlignment="Stretch" **Margin="0 4 0 4"**>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="4"/>

                               <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Image Grid.Column="1" Source="../Styles/Images/icon-exception.png" 
     />

                        </Grid> 
                        <Rectangle x:Name="FocusVisualElement" RadiusY="4" RadiusX="4" Stroke="#FF6DBDD1"  StrokeThickness="0" Visibility="Collapsed" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

To help you more can you please just post u r code . :)

Malcolm