微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – NControl绘制方法没有触发

我最近发现了NGraphics& NControl库可以与Xamarin.Forms一起使用,到目前为止看起来很棒.

我遇到的问题是draw方法永远不会被调用,而且我不太确定我哪里出错了.我的代码在下面(我已经删除了所有不必要的位),非常感谢任何帮助!

public class CustomGrid : NControlView
    {
        public CustomGrid ()
        {
            base.Invalidate (); //Invalidating the control doesn't redraw the control
            Content = new Label {BackgroundColor = Xamarin.Forms.Color.Transparent};
            BackgroundColor = Xamarin.Forms.Color.Blue;
        }


        public override void Draw (NGraphics.ICanvas canvas,NGraphics.Rect rect)
        {
            base.Draw(canvas,rect);
            //foreach column draw the grid line on the right
            foreach (CustomColumn c in ColumnCollection) 
            {
                canvas.DrawLine (c.CoOrds.startX,c.CoOrds.startY,c.CoOrds.EndX,c.CoOrds.EndY,Colors.White);
            }

            //for each row draw the bottom grid line
            foreach (Customrow r in RowCollection) 
            {
                canvas.DrawLine (r.CoOrds.startX,r.CoOrds.startY,r.CoOrds.EndX,r.CoOrds.EndY,Colors.White);
            }
        }

        public List<CustomColumn> ColumnCollection { get; set; }
        public List<Customrow> RowCollection { get; set; }


    }

为了确保我不会发疯,我复制并粘贴了NControl GitHub Repo上的示例,但似乎也没有用.

先感谢您!

解决方法

>确保在Forms.Init()之后调用NControlVieWrenderer.Init()
>在public override void Draw(NGraphics.ICanvas canvas,NGraphics.Rect rect)中,你不一定需要调用base.Draw()
>尝试调用CustomGrid.Invalidate(),这应该强制重绘
>确保你的控件实际上在屏幕上,在视口内并且大小大于0,你可以给它一个粉红色的背景,看看它是否显示在任何地方……
>为什么你说它到目前为止似乎很棒.什么时候显然没有?比如,实际工作的那部分是什么?
>在子类’ctor中设置一个断点,看看它是否实际被实例化了……

这些都有帮助吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐