列表框中的粘滞文本 - wp8

时间:2015-06-26 15:40:48

标签: c# windows-phone-8 listbox

我将项目成功添加到列表框,但它们之间的正常空间,它们粘在一起。任何人都可以帮我解决这个问题吗?

 <ListBox Name="mylistbox" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" >
                        <ListBox.ItemTemplate>
                        <DataTemplate>
                            <!--<StackPanel Name="s1">-->
                            <Grid Name="g1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="10*"/>
                                        <ColumnDefinition Width="30*"/>
                                        <ColumnDefinition Width="30*"/>
                                        <ColumnDefinition Width="30*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="50"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding redni2}"  FontSize="26" Grid.Row="0" Grid.Column="0"/>
                                    <TextBlock Text="{Binding ime}"  FontSize="26" Grid.Row="0" Grid.Column="1"/>
                                    <TextBlock Text="{Binding broj2}"  FontSize="26" Grid.Row="0" Grid.Column="2"/>
                                    <TextBlock Text="{Binding ukupno2}"  FontSize="26" Grid.Row="0" Grid.Column="3"/>
                                </Grid>
                            <!--</StackPanel>-->
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

1 个答案:

答案 0 :(得分:0)

使用ListBox.ItemContainerStyle属性。试试这个:

<ListBox>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="0,0,0,9.5">
                <Grid Name="g1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="3*"/>
                        <ColumnDefinition Width="3*"/>
                        <ColumnDefinition Width="3*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="111" FontSize="26" Grid.Column="0"/>
                    <TextBlock Text="222" FontSize="26" Grid.Column="1"/>
                    <TextBlock Text="333" FontSize="26" Grid.Column="2"/>
                    <TextBlock Text="444" FontSize="26" Grid.Column="3"/>
                </Grid>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>