Display a list in Grid view for windows phone 8

微笑、不失礼 提交于 2020-01-05 08:06:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!