C# 将单独的列表绑定到一个列表框中
我想用从json web服务获得的单独列表数据绑定我的列表框,所以它看起来像这样:C# 将单独的列表绑定到一个列表框中,c#,xaml,mvvm,listbox,windows-phone,C#,Xaml,Mvvm,Listbox,Windows Phone,我想用从json web服务获得的单独列表数据绑定我的列表框,所以它看起来像这样: public List<Phone> phone { get; set; } public List<Fax> fax { get; set; } public List<Email> email { get; set; } public List<Website> website { get; set; } 公共列表电话{get;set;} 公用列表传真{get
public List<Phone> phone { get; set; }
public List<Fax> fax { get; set; }
public List<Email> email { get; set; }
public List<Website> website { get; set; }
公共列表电话{get;set;}
公用列表传真{get;set;}
公共列表电子邮件{get;set;}
公共列表网站{get;set;}
我想把所有的列表绑定到一个列表框中,这样我的列表框将在一个项目中包含电话、传真、电子邮件和网站。。。怎么做
编辑:我心目中的格式示例
电话:+04532534534
传真:+5234523453
电邮:user@user.com
网站:www.user.com
编辑:到目前为止,我的方法是将分隔列表放入分隔属性中,并将其放入我的mainviewmodel中
RootObjectDetail result = JsonConvert.DeserializeObject<RootObjectDetail>(e.Result);
if (result.contacts.email != null)
hereRestEmail = new ObservableCollection<Email>(result.contacts.email);
if (result.contacts.phone != null)
hereRestPhone = new ObservableCollection<Phone>(result.contacts.phone);
if (result.media.reviews.items != null)
hereRestReview = new ObservableCollection<ItemReview>(result.media.reviews.items);
if (result.media.images.items != null)
hereRestImage = new ObservableCollection<ItemImage>(result.media.images.items);
RootObjectDetail结果=JsonConvert.DeserializeObject(e.result);
如果(result.contacts.email!=null)
hereRestEmail=新的可观察收集(result.contacts.email);
如果(result.contacts.phone!=null)
hereRestPhone=新的可观察收集(result.contacts.phone);
if(result.media.reviews.items!=null)
HereresReview=新的可观察收集(结果、媒体、评论、项目);
if(result.media.images.items!=null)
hereRestImage=新的ObservableCollection(result.media.images.items);
但我只是不知道如何将它绑定到我的listbox datacontex中,因为我只能绑定其中一个属性
<telerikPrimitives:RadDataBoundListBox
x:Name="ContactListBox"
ItemsSource="{Binding hereRestPhone}">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding LocalizedResources.phone,
Mode=OneWay, Source={StaticResource LocalizedStrings}}"
Style="{StaticResource PhoneTextLargeStyle}"/>
<TextBlock Grid.Column="1" Text="{Binding value}"
Style="{StaticResource PhoneTextLargeStyle}" />
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
它只能显示phone only,我仍然不知道如何将传真、电子邮件和网站绑定到此列表框中如果不知道您的课程内部是什么样子,我只能猜测:
var allValues =
phone.Select(x => new { Type = "phone", Value = x.PhoneNumber })
.Concat(fax.Select(x => new { Type = "fax", Value = x.FaxNumber }))
.Concat(email.Select(x => new { Type = "email", Value = x.EmailAddr }))
.Concat(website.Select(x => new { Type = "website", Value = x.URL }))
.ToList();
您将得到一个带有“Type”和“Value”的(匿名类型)列表
我还没有测试过这个,但是你应该能够在你的XAML中设置一个模板,绑定到“Type”和“Value”,并让它们像你上面所说的那样显示出来。我已经将它编辑成我心目中的列表格式,所以对于我列表中的每个项目都是这样的。。。示例是列表项1,对于项2和3,它将与之类似,但电话、传真、电子邮件和网站的值不同。哇,这是我以前从未见过的语法。。。介意给我一些关于这个语法的参考吗?嗯,我想你把concat语句的链接放错了,因为它让我跳进了与LINQ相同的链接…,读了一段时间后,LINQ是某种数据库/sql,所以我不明白为什么可以用它来解决我的问题。。也许你可以看到我的文章(已经编辑)的更多细节