AbsoluteLayout.Children 컬렉션의 RemoveAt 메서드를 사용하는 다음 스 니펫을 시도해보십시오.
또는 변수 참조가있는 경우 제거 (보기) 방법을 사용할 수 있습니다.
StackLayout objStackLayout = new StackLayout()
{
};
//
AbsoluteLayout objAbsoluteLayout = new AbsoluteLayout()
{
};
//
BoxView objBox1 = new BoxView()
{
Color = Color.Red,
WidthRequest = 50,
HeightRequest = 50,
};
objAbsoluteLayout.Children.Add(objBox1, new Point(100,100));
System.Diagnostics.Debug.WriteLine("Children Count : " + objAbsoluteLayout.Children.Count);
//
BoxView objBox2 = new BoxView()
{
Color = Color.Green,
WidthRequest = 50,
HeightRequest = 50,
};
objAbsoluteLayout.Children.Add(objBox2, new Point(200, 200));
System.Diagnostics.Debug.WriteLine("Children Count : " + objAbsoluteLayout.Children.Count);
//
Button objButton1 = new Button()
{
Text = "Remove First Child"
};
objButton1.Clicked += ((o2, e2) =>
{
if (objAbsoluteLayout.Children.Count > 0)
{
// To Remove a View at a specific index use:-
objAbsoluteLayout.Children.RemoveAt(0);
//
DisplayAlert("Children Count", objAbsoluteLayout.Children.Count.ToString(), "OK");
}
else
{
DisplayAlert("Invalid", "There are no more children that can be removed", "OK");
}
});
//
objStackLayout.Children.Add(objAbsoluteLayout);
objStackLayout.Children.Add(objButton1);
감사합니다. :-디 – kaolick