Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从Xamarin.Forms中的自定义呈现器获取对正在呈现的控件的引用?_C#_Android_Xamarin - Fatal编程技术网

C# 如何从Xamarin.Forms中的自定义呈现器获取对正在呈现的控件的引用?

C# 如何从Xamarin.Forms中的自定义呈现器获取对正在呈现的控件的引用?,c#,android,xamarin,C#,Android,Xamarin,我正在尝试使用Xamarin.Forms将OnFling连接到TextCell。我相信我已经正确地连接了事件,但是我不确定如何将控件的引用传递给侦听器对象 我主要想做以下几点: public class MyTextCell : TextCell { public void UserSwiped (SwipeDirection direction) { //Do Foo... } } [assembly: ExportRenderer (typeof(M

我正在尝试使用Xamarin.Forms将
OnFling
连接到
TextCell
。我相信我已经正确地连接了事件,但是我不确定如何将控件的引用传递给侦听器对象

我主要想做以下几点:

public class MyTextCell : TextCell
{
    public void UserSwiped (SwipeDirection direction)
    {
        //Do Foo...
    }
}

[assembly: ExportRenderer (typeof(MyTextCell), typeof(MyTextCellRenderer))]
public class MyTextCellRenderer : TextCellRenderer
{
    private readonly MyTextCellListener _listener;
    private readonly GestureDetector _detector;

    public MyTextCellRenderer ()
    {
        _listener = new MyTextCellListener (MyTextCell); //Here I need to get the reference to the MyTextCell that the renderer is rendering...
        _detector = new GestureDetector (_listener);
    }
}

public class BincTextCellListener : GestureDetector.SimpleOnGestureListener
{
    public MyTextCellListener(MyTextCell cell)
    {
         Cell = cell;
    }

    MyTextCell Cell {get; set; }

    public override bool OnFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
        Cell.UserSwiped(SwipedDirection.SomeDirection);
    }
}
建议在重写
OnElementChanged()
时,我应该能够从
NewElement
对象获取引用。但是,
TextCellRenderer
没有要重写的方法。(它的等价物是
GetCellCore()
,但它也不包含
NewElement
属性。)


是否有人能够建议如何从
MyTextCellRenderer
访问
MyTextCell
对象?

GetCellCore的第一个参数是Xamarin.Forms.Cell,您应该能够将其强制转换为自定义MyTextCell

protected override View GetCellCore (Xamarin.Forms.Cell item, View convertView, ViewGroup parent, Context context)