public System.Drawing.PointF GetCoordinates(global::Xamarin.Forms.VisualElement element)
    {
        var renderer   = Platform.GetRenderer(element);
        var nativeView = renderer.NativeView;
        var rect       = nativeView.Superview.ConvertPointToView(nativeView.Frame.Location, null);

        return(new System.Drawing.PointF((int)Math.Round(rect.X), (int)Math.Round(rect.Y)));
    }
Exemple #2
0
        /// <summary>
        /// Determines whether a view should have conventions applied to it.
        /// </summary>
        /// <param name="view">The view to check.</param>
        /// <returns>Whether or not conventions should be applied to the view.</returns>
        public static bool ShouldApplyConventions(FrameworkElement view)
        {
            var overriden = View.GetApplyConventions(view);

            return(overriden.GetValueOrDefault(ApplyConventionsByDefault));

            return(false);
        }
Exemple #3
0
    public System.Drawing.PointF GetCoordinates(global::Xamarin.Forms.VisualElement element)
    {
        var renderer   = Platform.GetRenderer(element);
        var nativeView = renderer.View;
        var location   = new int[2];
        var density    = nativeView.Context.Resources.DisplayMetrics.Density;

        nativeView.GetLocationOnScreen(location);
        return(new System.Drawing.PointF(location[0] / density, location[1] / density));
    }
Exemple #4
0
        public System.Drawing.PointF GetCoordinates(global::Xamarin.Forms.VisualElement element)
        {
            var renderer   = XFPlatform.GetRenderer(element);
            var nativeView = renderer.NativeView;
            var rect       = nativeView.Superview.ConvertPointToView(nativeView.Frame.Location, null);
            var coord      = new System.Drawing.PointF((int)Math.Round(rect.X), (int)Math.Round(rect.Y));

            //Something is wrong with the calculation and must be adjusted by 91.5
            coord.Y = coord.Y - 91.5f;

            return(coord);
        }
Exemple #5
0
        public System.Drawing.PointF GetCoordinates(global::Xamarin.Forms.VisualElement element)
        {
            var renderer   = XFPlatform.GetRenderer(element);
            var nativeView = renderer.View;
            var location   = new int[2];
            var density    = nativeView.Context.Resources.DisplayMetrics.Density;

            nativeView.GetLocationOnScreen(location);
            var coord = new System.Drawing.PointF(location[0] / density, location[1] / density);

            //Something is wrong with the calculation and must be adjusted by 91.5
            coord.Y = coord.Y - 80.2f;

            return(coord);
        }
        ///<summary>
        ///  Uses the action pipeline to invoke the method.
        ///</summary>
        ///<param name="target"> The object instance to invoke the method on. </param>
        ///<param name="methodName"> The name of the method to invoke. </param>
        ///<param name="view"> The view. </param>
        ///<param name="source"> The source of the invocation. </param>
        ///<param name="eventArgs"> The event args. </param>
        ///<param name="parameters"> The method parameters. </param>
        public static void Invoke(object target, string methodName, DependencyObject view = null, FrameworkElement source = null, object eventArgs = null, object[] parameters = null) {

            var message = new ActionMessage {MethodName = methodName};

            var context = new ActionExecutionContext {
                Target = target,
#if WinRT
                Method = target.GetType().GetRuntimeMethods().Single(m => m.Name == methodName),
#else
                Method = target.GetType().GetMethod(methodName),
#endif
                Message = message,
                View = view,
                Source = source,
                EventArgs = eventArgs
            };

            if (parameters != null) {
                parameters.Apply(x => context.Message.Parameters.Add(x as Parameter ?? new Parameter { Value = x }));
            }

            ActionMessage.InvokeAction(context);

            // This is a bit of hack but keeps message being garbage collected
            Log.Info("Invoking action {0} on {1}.", message.MethodName, target);
        }
        ///<summary>
        ///  Uses the action pipeline to invoke the method.
        ///</summary>
        ///<param name="target"> The object instance to invoke the method on. </param>
        ///<param name="methodName"> The name of the method to invoke. </param>
        ///<param name="view"> The view. </param>
        ///<param name="source"> The source of the invocation. </param>
        ///<param name="eventArgs"> The event args. </param>
        ///<param name="parameters"> The method parameters. </param>
        public static void Invoke(object target, string methodName, DependencyObject view = null, FrameworkElement source = null, object eventArgs = null, object[] parameters = null)
        {
            var message = new ActionMessage {
                MethodName = methodName
            };

            var context = new ActionExecutionContext {
                Target = target,
#if WinRT
                Method = target.GetType().GetRuntimeMethods().Single(m => m.Name == methodName),
#else
                Method = target.GetType().GetMethod(methodName),
#endif
                Message   = message,
                View      = view,
                Source    = source,
                EventArgs = eventArgs
            };

            if (parameters != null)
            {
                parameters.Apply(x => context.Message.Parameters.Add(x as Parameter ?? new Parameter {
                    Value = x
                }));
            }

            ActionMessage.InvokeAction(context);

            // This is a bit of hack but keeps message being garbage collected
            Log.Info("Invoking action {0} on {1}.", message.MethodName, target);
        }
 /// <summary>
 /// Determines whether a view should have conventions applied to it.
 /// </summary>
 /// <param name="view">The view to check.</param>
 /// <returns>Whether or not conventions should be applied to the view.</returns>
 public static bool ShouldApplyConventions(FrameworkElement view) {
     var overriden = View.GetApplyConventions(view);
     return overriden.GetValueOrDefault(ApplyConventionsByDefault);
 }