C# Windows Phone上的Listview:项目列表不正确

C# Windows Phone上的Listview:项目列表不正确,c#,xaml,data-binding,windows-phone-8.1,viewmodel,C#,Xaml,Data Binding,Windows Phone 8.1,Viewmodel,我的要求是实现一个国家的名单,让我的用户选择和他们的电话号码。 在我绝望的尝试中,我跟随的是那篇文章。 我的ListView设置如下: 国家名称是试用的,因此没有意义 ViewModel:我硬编码的国家列表 //Contructor class public CountryList_test() { //Creating static data memberrs (Hardcoded logic) var list_countryList = n

我的要求是实现一个国家的名单,让我的用户选择和他们的电话号码。 在我绝望的尝试中,我跟随的是那篇文章。 我的ListView设置如下:

国家名称是试用的,因此没有意义

ViewModel:我硬编码的国家列表

//Contructor class public CountryList_test() { //Creating static data memberrs (Hardcoded logic) var list_countryList = new List { new CountryList_CountryNames{countryName = "ffsdfndf"}, new CountryList_CountryNames{countryName = "hfhjf"}, new CountryList_CountryNames{countryName = "vcxbv"}, new CountryList_CountryNames{countryName = "ujhfg"}, new CountryList_CountryNames{countryName = "vbcvb"}, new CountryList_CountryNames{countryName = "fdfgd"}, new CountryList_CountryNames{countryName = "dfdhgfjjyhg"}, new CountryList_CountryNames{countryName = "khjkj"}, new CountryList_CountryNames{countryName = "fffg"}, }; //Grouping the country names var countriesByCategories = list_countryList.GroupBy(x => x.countryName).Select(x => new CountryList_GroupMechanism { countryNameForGroupMechanism = x.Key,countryListForGroupMechanism = x.ToList() }); countryListForGroupMechanism = countriesByCategories.ToList(); } public class CountryList_CountryNames { public string countryName { get; set; } //public int internationalCode { get; set; } } public class CountryList_GroupMechanism { public string countryNameForGroupMechanism { get; set; } public List countryListForGroupMechanism { get; set; } } } //构造函数类 公共国家列表_测试() { //创建静态数据成员(硬编码逻辑) var list\u countryList=新列表 { 新的CountryList_CountryNames{countryName=“ffsdfndf”}, 新的CountryList_CountryNames{countryName=“hfhjf”}, 新的CountryList_CountryNames{countryName=“vcxbv”}, 新的CountryList_CountryNames{countryName=“ujhfg”}, 新的CountryList_CountryNames{countryName=“vbcvb”}, 新的CountryList_countryName{countryName=“fdfgd”}, 新的CountryList_countryName{countryName=“dfdhgfjjyhg”}, 新的CountryList_CountryNames{countryName=“khjkj”}, 新的CountryList_countryName{countryName=“fffg”}, }; //将国家名称分组 var countriesByCategories=list\u countryList.GroupBy(x=>x.countryName)。选择(x=>newcountrylist\u GroupMechanism{countryNameForGroupMechanism=x.Key,countryListForGroupMechanism=x.ToList()}); countryListForGroupMechanism=countriesByCategories.ToList(); } 公共类CountryList\u CountryNames { 公共字符串countryName{get;set;} //公共int国际代码{get;set;} } 公共类CountryList\u组机制 { 公共字符串countryNameForGroupMechanism{get;set;} 公共列表countryListForGroupMechanism{get;set;} } }
这看起来不错。
这是我的模型:它位于类Bpage2的构造函数中
This is my View:

        <!--countryListForGroupMechanism comes from the ViewModel-->
        <ListView Name="lstv_countries" 

                  ItemsSource="{Binding countryListForGroupMechanism}" >

        </ListView>
公共Bpage2() { //创建视图模型的实例并将其设置为页面的数据上下文 this.InitializeComponent(); var viewModel=newcountrylist_test(); this.DataContext=viewModel; }

这是我的观点:
这是我的输出,让我发疯。我确信问题在V-M层面,但我不知道在哪里


请帮我找出问题所在。提前感谢:)

如果希望看到国家名称,请设置DisplayMemeberPath,因此应执行以下操作:

<ListView Name="lstv_countries" ItemsSource="{Binding countryListForGroupMechanism}" >
   <ListView.ItemTemplate>
        <DataTemplate>
           <TextBlock Text="{Binding Path=countryNameForGroupMechanism}"/>
       </DataTemplate>
   </ListView.ItemTemplate>
</ListView>

很抱歉格式化。不知道是怎么发生的。很抱歉我错过了:这里是:public List countryListForGroupMechanism{get;set;}。所以它是一个列表。DisplayMemeberPath和ItemTemplate都不起作用。它只显示一个空白屏幕。里面没有东西。“出什么事了?”匿名者,现在?!我不太懂你的模型
<ListView Name="lstv_countries" DisplayMemeberPath="countryNameForGroupMechanism"
          ItemsSource="{Binding countryListForGroupMechanism}" >
</ListView>
<ListView Name="lstv_countries" ItemsSource="{Binding countryListForGroupMechanism}" >
   <ListView.ItemTemplate>
        <DataTemplate>
           <TextBlock Text="{Binding Path=countryNameForGroupMechanism}"/>
       </DataTemplate>
   </ListView.ItemTemplate>
</ListView>