编辑:这是一个Windows应用商店(8.1)应用程序
我有一个人类,如下所示我用作模型
public class Person : BaseModel
{
private string _FirstName;
public string FirstName
{
get { return _FirstName; }
set
{
if (_FirstName == value)
return;
_FirstName = value;
RaisePropertyChanged("FirstName");
}
}
private string _MiddleName;
public string MiddleName
{
get { return _MiddleName; }
set
{
if (_MiddleName == value)
return;
_MiddleName = value;
RaisePropertyChanged("MiddleName");
}
}
private string _LastName;
public string LastName
{
get { return _LastName; }
set
{
if (_LastName == value)
return;
_LastName = value;
RaisePropertyChanged("LastName");
}
}
}
其中BaseModel定义如下
using GalaSoft.MvvmLight;
public class BaseModel: ObservableObject
{
}
我在ViewModel类中使用Model,如下所示。
using GalaSoft.MvvmLight;
public class PersonViewModel : ViewModelBase
{
/// <summary>
/// List of searched People
/// </summary>
private ObservableCollection<Person> _People;
public ObservableCollection<Person> People
{
get { return _People; }
set
{
if (_People== value)
return;
_People= value;
RaisePropertyChanged("People");
}
}
}
我将People集合绑定到GridView,如下所示。
<GridView
x:Name="PeopleSearchResultsGridView"
ItemsSource="{Binding People}">
</GridView>
搜索完成后,我会返回一个人员列表,我将其添加到列表中,如下所示。
var list = await p.SearchPeople();
People = new ObservableCollection<Person>(list);
我看到People集合的setter正在触发,而RaisePropertyChanged(“People”)事件也在触发,但是没有更新GridView。谁能告诉我这里有什么问题?