WPF ListView多列行

时间:2015-07-09 10:04:18

标签: wpf listview

我有这个型号:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
 [formatter setDateFormat:@"hh:mm a"];

目前,每个Public Data { string name; string age; string id; DateTime time; } 行包含所有这4个人员:

ListView

现在我想让这个<ListView.View> <GridViewColumn Width="20" DisplayMemberBinding="{Binding Index}" /> <GridViewColumn Width="320" DisplayMemberBinding="{Binding Description}" /> <GridViewColumn Width="150" DisplayMemberBinding="{Binding IPAddress}" /> <GridViewColumn Width="150" DisplayMemberBinding="{Binding time}" /> </GridView> </ListView.View> ListView变小,所以我希望每个Width包含2列,每列有2个属性。 有可能吗?

2 个答案:

答案 0 :(得分:1)

您需要覆盖GridViewColumn的默认CellTemplate,以便在ListView.View中显示结果

<GridViewColumn >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>                            
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Text="{Binding Index}" />
                                        <TextBlock Text="{Binding Description}"/>
                                    </StackPanel>                                    
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="{Binding IPAddress}" />
                                    <TextBlock Text="{Binding time}"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

答案 1 :(得分:0)

不要使用ListView

ListBox DataTemplate与网格

一起使用