簡體   English   中英

將對象模型綁定到xamarin形式的UI

[英]Bind Object Model to UI in xamarin forms

我有一個對象模型類(將desarlise json映射到對象模型),我想使用xamarin形式使用綁定將對象模型附加到UI。

PS不是本機也不是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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM