MVVM 绑定 属性 个对象
MVVM Binding a property of object
绑定有问题,如果我绑定字符串类型 属性 一切正常,但如果我尝试绑定查看 属性 的对象 属性 xaml 不上传。
没有任何错误或警告。
更新模型
型号:
public class Part : BindableObject
{
public int Id { get; set; }
public string Brand { get; set; }
public string _BrandImage;
public string BrandImage
{
get { return _BrandImage; }
set
{
_BrandImage = value;
OnPropertyChanged();
}
}
public string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
OnPropertyChanged();
}
}
public string Article { get; set; }
public string Mfg { get; set; }
public string Image { get; set; }
public string Description { get; set; }
public List<Offer> Offers { get; set; }
};
return result;
}
}
视图模型:
public class PartDetailViewModel : BindableBase
{
private Part part;
public Part Part
{
get { return part; }
set { SetProperty(ref part, value); }
}
public PartDetailViewModel(INavigationService navigationService)
{
Part = part.GetPartById();
}
}
您需要继承 'BindableObject' 并通知视图有关 setter 'set {}' 内部更改的 属性 对于您在视图中绑定的属性。我已经修改了您下面的名称 属性 代码,您可以根据您对其他字段的要求进行更改。
public class Part : BindableObject
{
public int Id { get; set; }
public string Brand { get; set; }
public string BrandImage { get; set; }
private string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
OnPropertyChanged();
}
}
public string Article { get; set; }
public string Mfg { get; set; }
public string Image { get; set; }
public string Description { get; set; }
public List<Offer> Offers { get; set; }
}
从模型中删除此 属性,这很有帮助
public List<Offer> Offers { get; set; }
绑定有问题,如果我绑定字符串类型 属性 一切正常,但如果我尝试绑定查看 属性 的对象 属性 xaml 不上传。
没有任何错误或警告。
更新模型
型号:
public class Part : BindableObject
{
public int Id { get; set; }
public string Brand { get; set; }
public string _BrandImage;
public string BrandImage
{
get { return _BrandImage; }
set
{
_BrandImage = value;
OnPropertyChanged();
}
}
public string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
OnPropertyChanged();
}
}
public string Article { get; set; }
public string Mfg { get; set; }
public string Image { get; set; }
public string Description { get; set; }
public List<Offer> Offers { get; set; }
};
return result;
}
}
视图模型:
public class PartDetailViewModel : BindableBase
{
private Part part;
public Part Part
{
get { return part; }
set { SetProperty(ref part, value); }
}
public PartDetailViewModel(INavigationService navigationService)
{
Part = part.GetPartById();
}
}
您需要继承 'BindableObject' 并通知视图有关 setter 'set {}' 内部更改的 属性 对于您在视图中绑定的属性。我已经修改了您下面的名称 属性 代码,您可以根据您对其他字段的要求进行更改。
public class Part : BindableObject
{
public int Id { get; set; }
public string Brand { get; set; }
public string BrandImage { get; set; }
private string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
OnPropertyChanged();
}
}
public string Article { get; set; }
public string Mfg { get; set; }
public string Image { get; set; }
public string Description { get; set; }
public List<Offer> Offers { get; set; }
}
从模型中删除此 属性,这很有帮助
public List<Offer> Offers { get; set; }