This doc은 Android, iOS 등을 위해 맞춤형 PageRenderer를 만드는 방법을 설명합니다. 문서별로 시도했지만 Android 용으로 작동하지 않는 이유는 알 수 없습니다. 그러나 iOS에서 작동합니다. 안드로이드에 대한Xamarin.Forms Android 사용자 정의 ContentPage PageRenderer보기를 렌더링하지 않습니다.
public class SecondPage : ContentPage
{
public SecondPage()
{
Content = new StackLayout
{
Children = {
new Label { Text = "Hello ContentPage" }
}
};
}
}
사용자 정의 PageRenderer 클래스 :
공유 ContentPage 클래스
[assembly: ExportRenderer(typeof(SecondPage), typeof(SecondPageRenderer))]
namespace RenderFormsTest.Droid
{
public class SecondPageRenderer : PageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
InitView();
}
void InitView()
{
var context = Forms.Context;
string[] os = { "Android", "iOS", "Windows" };
var ll = new LinearLayout(context);
ll.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
ll.SetBackgroundColor(Android.Graphics.Color.IndianRed);
var rg = new RadioGroup(context);
for (int index = 0; index < os.Length; index++)
{
rg.AddView(new RadioButton(context) { Text = os[index] });
}
ll.AddView(rg);
AddView(ll);
}
}
}
당신이 무엇이 잘못되었는지 말해 주실 래요?
실제로 어떤 일이 발생했는지, 실제로 어떤 일이 일어 났는지 알려주세요. –
** @ GeraldVersluis ** 예상 결과는 SeconPage로 이동할 때 세 개의 라디오 버튼이 표시 (표시)되어야하는 RadioGroup보기입니다. 하지만 현재는 "Hello ContentPage"와 같은 ContentPage에서 렌더링 된 Label을 볼 수 있으며 다른 뷰는 표시되지 않습니다 (또는 플랫폼 별 사용자 정의 SecondPageRenderer 클래스에서 렌더링 됨). – user2618875
페이지 렌더러는 뷰 그룹 일 뿐이며, 사용자 정의보기, 어떤 일이 발생하는지 확인하십시오. – Bonelol