我从azure移动服务中提取数据,但是当我将数据填充到longlistselector时,它会抛出一个null引用异常。
private MobileServiceCollection<users, users> items;
private IMobileServiceTable<users> user =
App.MobileService.GetTable<users>();
items = await user
.Where(users => users.age == 20).ToCollectionAsync();
foreach (users usr in items.Cast<users>())
{
listui.ItemsSource.Add(usr.age);
}
listui.ItemsSource.Add(items.Cast<users>());
我甚至试图填充longlistselector直接传递items对象而不进行强制转换,但它只是给了&#34; users.age&#34;作为项目。但是项目数量是正确的。
listui.ItemsSource = items
XAML
<phone:LongListSelector x:Name="listui" HorizontalAlignment="Left" Height="151" VerticalAlignment="Top" Width="363" Margin="52,386,0,0" Background="#FF787878"/>
帮助!
答案 0 :(得分:1)
您需要设置DataTemplate和Binding,试试这个,
<phone:LongListSelector Name="listui" HorizontalAlignment="Left" VerticalAlignment="Top" LayoutMode="List" IsGroupingEnabled="False" Width="446">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding age}" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>