StackLayout
변수의 데이터를 클래스 속성에 바인딩하는 방법이 있지만 불행히도 그것에 대한 리소스를 찾지 못했습니다. 간단한 바인딩을 구현하는 방법을 안다. 예 : Editor
과 Label
사이 그러나 Editor
입력 텍스트를 클래스 속성 예 : string Number {get; set;}
에 바인딩하려면 어떻게해야합니까? 다음은 클래스입니다.Xamarin.Forms 클래스 속성에 대한 데이터 바인딩
public class ThingsObject
{
public int Id { get; set; }
public bool IsStarted { get; set; }
public string Number {get; set; }
public string City { get; set; }
public Zones Zone { get; set; }
public ContentPage Page;
public DateTime StartDate { get; set; }
}
여기에는 StackLayout 구현, 변수 및 바인딩이 포함 된 PageLayout 클래스가 있습니다. 내가 things
Number
Editor
삽입 값으로 기존 개체에 바인딩하고 싶은
public partial class ThingPageLayout : CarouselPage
{
List<ThingsObject> things= new List<ThingsObject>();
public ThingPageLayout()
{
things.Add(new ThingsObject() { Id = 1, Number = null, City = null, Zone = null });
foreach (ThingsObject p in things)
{
Children.Add(CreatePage(p));
}
}
public ContentPage CreatePage(ThingsObject thing)
{
int uniqueId = this.IdPark;
var page = new ContentPage()
{
Content = new StackLayout { }
};
var label1 = new Label
{
Text = "Text",
TextColor = Color.Black,
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
HorizontalOptions = LayoutOptions.Center
};
((StackLayout)page.Content).Children.Add(label1);
var inputText = new Editor
{
TextColor = Color.Blue,
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill
};
((StackLayout)page.Content).Children.Add(inputText);
// Binding here //
label1.BindingContext = inputText;
label1.SetBinding(Label.TextProperty, "Text");
// End of binding //
var activeButton = new Button
{
ClassId = uniqueId.ToString(),
Text = "Button",
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill
};
((StackLayout)page.Content).Children.Add(activeButton);
thing.Page = page;
return page;
}
}
그리고 여기. 프로젝트가 시작될 때, Number
값이 null
이지만, Editor
입력 후에, 삽입 된 텍스트를 내 클래스 속성 Number
에 바인드하려고합니다.