问题
How Can I display a list in two columns for an application in windows phone 8?
items.xaml.cs:
public async void Initi()
{
var itemsManagement = new ItemsManagement();
var itemList = await itemsManagement.GetAllItems();
var templist = from c in itemList.Data orderby c.Name, c.Id ascending select c;
NameList.ItemsSource = templist;
}
items.xaml :
<ListBox x:Name="NameList">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}">
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This solution displays my list in one column, I would like a display in two columns
回答1:
Use a LongListSelector, and set LayoutMode to Grid and GridCellSize to half the page width.
<phone:LongListSelector
LayoutMode="Grid"
GridCellSize="200,20"
ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource ItemTemplate}"
</phone:LongListSelector>
回答2:
have you tried to do in this way:
<ListBox x:Name="NameList">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" Width="200"/>
<TextBlock Text="{Binding Path=Id}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
来源:https://stackoverflow.com/questions/15479826/display-a-list-in-grid-view-for-windows-phone-8