This docをレンダリングしていないが、私は、ドキュメントごとにしようとしたのAndroid、iOS搭載などのカスタムPageRendererを作成する方法について説明しますが、それはAndroidのために働いていない理由を知りません。ただし、iOSでは動作します。Xamarin.Forms AndroidのカスタムContentPage PageRendererがビュー
共有ContentPageクラス:Android用
public class SecondPage : ContentPage
{
public SecondPage()
{
Content = new StackLayout
{
Children = {
new Label { Text = "Hello ContentPage" }
}
};
}
}
カスタムPageRendererクラス:
[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に移動すると3つのラジオボタンが表示(レンダリング)されるラジオグループビューです。しかし、現在のところ、LabelはContentPage(つまり "Hello ContentPage")からレンダリングされ、他のビューは表示されません(またはプラットフォーム固有のカスタムSecondPageRendererクラスからレンダリングされます)。 – user2618875
Androidでは、ページレンダラーはビューグループに過ぎません。カスタムビュー、何が起こるかを見てください – Bonelol