开发者

Change the spacing on a listbox control in silverlight

Space between items is开发者_如何学Python to much. how can I lessen it?


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.


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.


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 . :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜