将列表框划分为多个带标题的列

时间:2016-11-24 18:52:13

标签: c# wpf

我试图将列表框划分为多个列,以便通过调用Listbox.items.add(item);添加项目,它将在不同的列中显示不同的属性。到目前为止,这是我的代码:

 <ListBox Name="listbox1" HorizontalContentAlignment="Stretch" Padding="2">
        <ListBox.ItemTemplate>
            <DataTemplate DataType="local:ScheduledEvent">
                <Grid Margin="0 5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>                            
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" Margin="3 0 3 0" FontFamily="Helvetica" FontSize="18" Text="{Binding WorldRank}"/>
                    <TextBlock Grid.Column="1" Text="{Binding Name}"/>
                    <TextBlock Grid.Column="2" Text="{Binding Surname}"/>
                    <TextBlock Grid.Column="3" Text="{Binding Age}"/>
                    <TextBlock Grid.Column="4" Text="{Binding Country}"/>
                    <TextBlock Grid.Column="5" Text="{Binding GraduationYear}"/>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

0 个答案:

没有答案