如何在WinRT Metro应用程序中绑定ListView内部的ListView
我的应用程序中有两个列表视图。 这是我的模型课如何在WinRT Metro应用程序中绑定ListView内部的ListView,listview,windows-phone-8.1,windows-8.1,winrt-xaml,Listview,Windows Phone 8.1,Windows 8.1,Winrt Xaml,我的应用程序中有两个列表视图。 这是我的模型课 public class SurveyDetailViewModel : INotifyPropertyChanged { private int _RoomTypeId; private string _RoomType; public int RoomTypeId { get { return _RoomTypeId; } set {
public class SurveyDetailViewModel : INotifyPropertyChanged
{
private int _RoomTypeId;
private string _RoomType;
public int RoomTypeId
{
get { return _RoomTypeId; }
set
{
_RoomTypeId = value;
NotifyPropertyChanged("RoomTypeId");
}
}
public string RoomType
{
get { return _RoomType; }
set
{
_RoomType = value;
NotifyPropertyChanged("RoomType");
}
}
public ObservableCollection<SurveyProductDetails> SurveyProductDetails { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public class SurveyProductDetails : INotifyPropertyChanged
{
private Guid _RoomId;
private int _ProductTypeId;
private string _Title;
private string _Color;
private int _Quantity;
private int _QuantityInstalled;
private string _RoomDescription;
private string _ProductDescription;
private string _ProductSpecification;
public Guid RoomId
{
get { return _RoomId; }
set
{
_RoomId = value;
NotifyPropertyChanged("RoomId");
}
}
public int ProductTypeId
{
get { return _ProductTypeId; }
set
{
_ProductTypeId = value;
NotifyPropertyChanged("ProductTypeId");
}
}
public string Title
{
get { return _Title; }
set
{
_Title = value;
NotifyPropertyChanged("Title");
}
}
public string Color
{
get { return _Color; }
set
{
_Color = value;
NotifyPropertyChanged("Color");
}
}
public string ProductSpecification
{
get { return _ProductSpecification; }
set
{
_ProductSpecification = value;
NotifyPropertyChanged("ProductSpecification");
}
}
public string ProductDescription
{
get { return _ProductDescription; }
set
{
_ProductDescription = value;
NotifyPropertyChanged("ProductDescription");
}
}
public int Quantity
{
get { return _Quantity; }
set
{
_Quantity = value;
NotifyPropertyChanged("Quantity");
}
}
public int QuantityInstalled
{
get { return _QuantityInstalled; }
set
{
_QuantityInstalled = value;
NotifyPropertyChanged("QuantityInstalled");
}
}
public string RoomDescription
{
get { return _RoomDescription; }
set
{
_RoomDescription = value;
NotifyPropertyChanged("RoomDescription");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
还有像这样的
ItemsSource="{Binding surveyDetail.SurveyProductDetails}"
我也试过用这个来做一个
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SurveyProductDetails}"
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=surveyDetail.SurveyProductDetails}"
外部ListView工作正常,但内部ListView根本没有绑定。我做错了什么需要帮助。假设页面已绑定到viewmodel,则可以使用此绑定
ItemsSource="{Binding SurveyProductDetails}"
我将SurveyProductDetails设置为只读属性,以确保在调用get时支持字段不为null 创建绑定到ObservableCollection的列表框时,该列表中的每个项都会被赋予datacontext,datacontext是集合中相应的对象。在这种情况下,每个顶级ListBoxItem都绑定到SurveyDetailViewModel类型的对象 因此,您的ItemsSource只需要:
{Binding SurveyProductDetails}
surveyDetail可以省略
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=SurveyProductDetails}"
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=surveyDetail.SurveyProductDetails}"
ItemsSource="{Binding SurveyProductDetails}"