public static View ConvertFormsToNative(this Xamarin.Forms.View view)
        {
            var vRenderer  = view.GetRenderer();
            var nativeView = vRenderer.View;

            return(nativeView);
        }
Пример #2
0
        private void HandleTouch(object sender, TouchEventArgs e)
        {
            switch (e.Event.Action)
            {
            case MotionEventActions.Down:
                var loc = GetPointF(e.Event);
                var o   = this.GetTouchedView(loc);
                this.touchedView = o != null ? o.Item1 : null;

                if (this.touchedView == this.Element.Content.GetNativeContent())
                {
                    this.touchedView = null;
                }

                if (this.touchedView != null)
                {
                    this.touchedElement = this.Element.Content.FindFormsViewFromAccessibilityId(this.touchedView);
                    this.homePosition   = new PointF(this.touchedView.GetX(), this.touchedView.GetY());
                    this.offsetLocation = new PointF(loc.X - o.Item2.X + homePosition.X, loc.Y - o.Item2.Y + homePosition.Y);
                }
                return;

            case MotionEventActions.Up:
                this.touchedView    = null;
                this.touchedElement = null;
                break;

            case MotionEventActions.Cancel:
                this.touchedView    = null;
                this.touchedElement = null;
                break;

            case MotionEventActions.Move:
                if (this.touchedView != null)
                {
                    var newLoc = GetPointF(e.Event);

                    var density = Application.Context.Resources.DisplayMetrics.Density;
                    var x       = (newLoc.X - this.offsetLocation.X) / density;
                    var y       = (newLoc.Y - this.offsetLocation.Y) / density;

                    if (this.touchedElement != null)
                    {
                        var f2 = new Rectangle(new Xamarin.Forms.Point(x, y),
                                               new Size(this.touchedElement.Width, this.touchedElement.Height));

                        this.touchedElement.Layout(f2);
                    }
                    //else
                    //{
                    //    this.touchedView.SetX(x);
                    //    this.touchedView.SetY(y);
                    //}
                }
                return;
            }
        }
        //http://www.michaelridland.com/xamarin/creating-native-view-xamarin-forms-viewpage/
        private ViewGroup ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size)
        {
            var vRenderer = Platform.CreateRenderer(view);
            var viewGroup = vRenderer.ViewGroup;

            vRenderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return(viewGroup);
        }
Пример #4
0
        public static View ConvertFormsToNative(this Xamarin.Forms.View view, Context context, Rectangle size)
        {
            var vRenderer = Platform.CreateRendererWithContext(view, context);
            var viewGroup = vRenderer.View;

            vRenderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);

            return(viewGroup);
        }
        public static View ConvertFormsToNative(this Xamarin.Forms.View view, Context context)
        {
            var vRenderer = view.GetRenderer();

            if (vRenderer == null)
            {
                Platform.SetRenderer(view, Platform.CreateRendererWithContext(view, context));
                vRenderer = view.GetRenderer();
            }
            var nativeView = vRenderer.View;

            nativeView.RemoveFromParent();
            vRenderer.Tracker.UpdateLayout();
            return(nativeView);
        }
        public static View ConvertFormsToNative(Context context, Xamarin.Forms.View view, Size size, float density)
        {
            if (view == null)
            {
                return(null);
            }
            if (Platform.GetRenderer(view) == null)
            {
                Platform.SetRenderer(view, Platform.CreateRendererWithContext(view, context));
            }

            var vRenderer  = Platform.GetRenderer(view);
            var nativeView = vRenderer.View;
            var dpW        = size.Width > 0 ? ConvertDpToPixels(size.Width, density) : ViewGroup.LayoutParams.WrapContent;
            var dpH        = size.Height > 0 ? ConvertDpToPixels(size.Height, density) : ViewGroup.LayoutParams.WrapContent;

            nativeView.LayoutParameters = new ViewGroup.LayoutParams(dpW, dpH);

            return(nativeView);
        }