以xamarin形式将对象模型绑定到UI
本文关键字:绑定 UI 对象模型 xamarin | 更新日期: 2023-09-27 18:26:10
我有一个对象模型类(desarlise json到对象模型),我想使用xamarin表单使用绑定将对象模型附加到UI。
p.S不是原生的,也不是XAML,而是通过代码。
在互联网上搜索,但它越来越令人困惑
任何帮助都会给带来极大的帮助
感谢
您的问题有点不清楚,但这里有一个代码中Xamarin.Forms
的数据绑定示例。
//INPC implementation removed in this sample
public class PersonViewModel
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
var person = new PersonViewModel {
FirstName = "John",
LastName = "Doe",
};
var first = new Label ();
first.SetBinding (Label.TextProperty, "FirstName");
var label = new Label ();
label.SetBinding (Label.TextProperty, "LastName");
var personView = new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
first,
last
}
};
personView.BindingContext = person;