/// <summary>
        /// Utility function to find the first containing <see cref="GesturesContentView"/>
        /// </summary>
        /// <param name="view">View to find the parent from.</param>
        /// <param name="throwException">True to throw an excpetion if the parent is not found</param>
        /// <returns></returns>
        private static GesturesContentView FindContentViewParent(View view, bool throwException=true)
        {
            var history = new List<string>();
            var viewParent = view as GesturesContentView;
            if (viewParent != null) return viewParent;

            history.Add(view.GetType().Name);
            var parent = view.Parent;
            while (parent != null && !(parent is GesturesContentView))
            {
                history.Add(parent.GetType().Name);
                parent = parent.Parent;
            }

            if (parent == null && throwException)
            {
                throw new InvalidNestingException(typeof (Gestures), typeof (GesturesContentView), history);
            }

            return (GesturesContentView) parent;
        }
Пример #2
0
 public static void UniversalAdjustments(Xamarin.Forms.View startingView)
 {
     if (startingView.GetType() == typeof(Grid))
     {
         var grid = (Grid)startingView;
         if (grid.RowDefinitions != null)
         {
             foreach (var rowDef in grid.RowDefinitions)
             {
                 if (rowDef.Height.IsAbsolute)
                 {
                     rowDef.Height = rowDef.Height.Value * _fontSizeRatio;
                 }
             }
         }
         if (grid.ColumnDefinitions != null)
         {
             foreach (var colDef in grid.ColumnDefinitions)
             {
                 if (colDef.Width.IsAbsolute)
                 {
                     colDef.Width = colDef.Width.Value * _fontSizeRatio;
                 }
             }
         }
         foreach (var item in grid.Children)
         {
             if (item.GetType() == typeof(StackLayout))
             {
                 StackLayoutAdjustments((StackLayout)item);
             }
             else if (item.GetType() == typeof(Button))
             {
                 SetButtonAttributes((Button)item);
             }
             else if (item.GetType() == typeof(Label))
             {
                 SetLabelFontAttributes((Label)item);
             }
             else if (item.GetType() == typeof(Entry))
             {
                 EntryAdjustments((Entry)item);
             }
             else if (item.GetType() == typeof(Grid))
             {
                 UniversalAdjustments(item);
             }
         }
     }
     else if (startingView.GetType() == typeof(StackLayout))
     {
         StackLayoutAdjustments((StackLayout)startingView);
     }
     else if (startingView.GetType() == typeof(Frame))
     {
         foreach (var ctl in ((Frame)startingView).Children)
         {
             UniversalAdjustments((Xamarin.Forms.View)ctl);
         }
     }
     else if (startingView.GetType() == typeof(AbsoluteLayout))
     {
         foreach (var ctl in ((AbsoluteLayout)startingView).Children)
         {
             UniversalAdjustments(ctl);
         }
     }
     else if (startingView.GetType() == typeof(ContentView))
     {
         foreach (var ctl in ((ContentView)startingView).Children)
         {
             UniversalAdjustments((Xamarin.Forms.View)ctl);
         }
     }
 }