Xamarin Forms Custom Renderer for Android不显示 [英] Xamarin Forms Custom Renderer for Android not displaying

查看:83
本文介绍了Xamarin Forms Custom Renderer for Android不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Xamarin Forms应用程序中呈现一个复选框.据我所知,运行时没有渲染任何东西,甚至告诉渲染器都没有被调用.

I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.

有人知道我在想什么或做错了吗?

Does anyone understand what I am missing or doing incorrectly?

这是我在Forms中的课程:

Here is my class in Forms:

public class LegalCheckbox : View
{
    public LegalCheckbox ()
    {

    }
}

还有我在Droid中的自定义渲染器类:

And my custom renderer class in Droid:

public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
    protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
    {
        base.OnElementChanged (e);
        CheckBox control = new Android.Widget.CheckBox(this.Context);
        control.Checked = false;
        control.Text = "I agree to terms";
        control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
        this.SetNativeControl(control);
    }
}

关于汇编指令:

[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]

推荐答案

检查代码并使用它启动一个新项目.该代码似乎可以正常工作.

Took your code and fired up a new project with it. The code appears to function fine.

只有一个瘦我可以认为可能导致您出现问题的是程序集属性的位置.我通常将它们放在与渲染器相同的文件中的名称空间声明的上方.

Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.

我将我在github上创建的内容扔了出来,也许您可​​以发现其中的区别.

I threw what I created up on my github maybe you can spot the difference.

https://github.com/DavidStrickland0/Xamarin-Forms-样本/树/主/RendererDemo

@Thibault D. Xlabs并不是一个坏项目,但它基本上只是Xamarin.Forms生命的第一年左右开源社区提出的所有代码.它不是真正的他们的实验室项目",考虑到其中有多少用Alpha Beta标记,以及其问题页面中的错误数量,最好不要暗示Xamarin公司与此有关.

@Thibault D. Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.

这篇关于Xamarin Forms Custom Renderer for Android不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆