private void DbgPrintProperties(View view, string CurrentIndent, ref string visualTree)
 {
     if (view is StackLayout)
     {
         StackLayout vw = (StackLayout)view;
         visualTree += string.Format("{0}Orientation=\"{1}\" HorizontalOptions=\"{2}\" VerticalOptions=\"{3}\"",
                                     CurrentIndent, vw.Orientation.ToString(), LayoutToString(vw.HorizontalOptions), LayoutToString(vw.VerticalOptions));
     }
     else if (view is SuperscriptText)
     {
         SuperscriptText vw = (SuperscriptText)view;
         visualTree += string.Format("{0}Text=\"{1}\"",
                                     CurrentIndent, vw.Text);
         //, vw.BackgroundColor, vw.TextColor
     }
     else if (view is Label)
     {
         Label vw = (Label)view;
         visualTree += string.Format("{0}Text=\"{1}\"",
                                     CurrentIndent, vw.Text);
     }
     else if (view is BoxView)
     {
         BoxView vw = (BoxView)view;
         visualTree += string.Format("{0}HeightRequest=\"{1}\" HorizontalOptions=\"{2}\"",
                                     CurrentIndent, vw.HeightRequest, LayoutToString(vw.HorizontalOptions));
         //Color={1} , vw.Color
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
        // ------------------------

        private View DisplayFunctionCalc(FunctionCalc expr, bool bSkipOpBrackets, Function lastFn)
        {
            bool bThisSkipOpBrackets = bSkipOpBrackets;
            bool bNextSkipOpBrackets = false;

            StackLayout stackLayout = new StackLayout
            {
                Orientation     = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
            };

            Function fn = expr.Function;

            if (fn is FnEquals)
            {
                bNextSkipOpBrackets = true;
            }

            if (fn.FuncLayout == FuncLayout.FuncLayout)
            {
                stackLayout.Children.Add(new FuncNameResultLabel
                {
                    Text            = fn.Symbol,
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                    SingleResult    = expr
                });

                stackLayout.Children.Add(new OpenBracketResultLabel
                {
                    Text            = "(",
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                    SingleResult    = expr
                });

                AddExpressionInputs(stackLayout, expr.Inputs);

                stackLayout.Children.Add(new CloseBracketResultLabel
                {
                    Text            = ")",
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                    SingleResult    = expr
                });
            }
            else if (fn.FuncLayout == FuncLayout.Op_Term)
            {
                bThisSkipOpBrackets = true;

                if (!bThisSkipOpBrackets)
                {
                    stackLayout.Children.Add(new OpenBracketResultLabel
                    {
                        Text            = "(",
                        VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                        SingleResult    = expr
                    });
                }

                stackLayout.Children.Add(new OpResultLabel
                {
                    Text            = fn.Symbol,
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                    SingleResult    = expr
                });

                stackLayout.Children.Add(DisplayMathExpression(expr.Inputs[0], bSkipOpBrackets: bNextSkipOpBrackets, lastFn: fn));

                if (!bThisSkipOpBrackets)
                {
                    stackLayout.Children.Add(new CloseBracketResultLabel
                    {
                        Text            = ")",
                        VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                        SingleResult    = expr
                    });
                }
            }
            else if (fn.FuncLayout == FuncLayout.Term_Op_Term)
            {
                if (fn == lastFn)        // is Functions.FnMultiply)
                {
                    bThisSkipOpBrackets = true;
                }
                if (!bThisSkipOpBrackets)
                {
                    stackLayout.Children.Add(new OpenBracketResultLabel
                    {
                        Text            = "(",
                        VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                        SingleResult    = expr
                    });
                }

                stackLayout.Children.Add(DisplayMathExpression(expr.Inputs[0], bSkipOpBrackets: bNextSkipOpBrackets, lastFn: fn));

                stackLayout.Children.Add(new OpResultLabel
                {
                    Text            = fn.Symbol,
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                    SingleResult    = expr
                });

                stackLayout.Children.Add(DisplayMathExpression(expr.Inputs[1], bSkipOpBrackets: bNextSkipOpBrackets, lastFn: fn));

                if (!bThisSkipOpBrackets)
                {
                    stackLayout.Children.Add(new CloseBracketResultLabel
                    {
                        Text            = ")",
                        VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                        SingleResult    = expr
                    });
                }
            }
            else if (fn.FuncLayout == FuncLayout.Term_OverOp_Term)
            {
                if (!(fn is FnDivide))
                {
                    // TODO: Equations: What else could it be? What do we show instead of a line?
                }

                if (!bThisSkipOpBrackets)
                {
                    stackLayout.Children.Add(new OpenBracketResultLabel
                    {
                        Text              = "(",
                        VerticalOptions   = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.Center,
                        SingleResult      = expr
                    });
                }

                StackLayout slVert = new StackLayout
                {
                    Orientation     = StackOrientation.Vertical,
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                };
                stackLayout.Children.Add(slVert);

                View vwTop = DisplayMathExpression(expr.Inputs[0], bSkipOpBrackets: bNextSkipOpBrackets, lastFn: fn);
                slVert.Children.Add(vwTop);

                BoxView boxView = new BoxView
                {
                    Color           = (Color)Application.Current.Resources[App.Key_TextColor],
                    HeightRequest   = _lineDepth,
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                };

                slVert.Children.Add(boxView);

                View vwBottom = DisplayMathExpression(expr.Inputs[1], bSkipOpBrackets: bNextSkipOpBrackets, lastFn: fn);
                slVert.Children.Add(vwBottom);

                MaxWidthBinder maxWidthBinder = new MaxWidthBinder(new List <View> {
                    vwTop, vwBottom
                });
                boxView.SetBinding(BoxView.WidthRequestProperty, new Binding()
                {
                    Source = maxWidthBinder, Path = "MaxWidth"
                });

                if (!bThisSkipOpBrackets)
                {
                    stackLayout.Children.Add(new CloseBracketResultLabel
                    {
                        Text              = ")",
                        VerticalOptions   = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.Center,
                        SingleResult      = expr
                    });
                }
            }
            else if (fn.FuncLayout == FuncLayout.Term_Superscript_Term)
            {
                StackLayout slHoriz = new StackLayout
                {
                    Orientation       = StackOrientation.Horizontal,
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,
                };
                stackLayout.Children.Add(slHoriz);

                View vw = DisplayMathExpression(expr.Inputs[0], bSkipOpBrackets: bNextSkipOpBrackets, lastFn: fn);
                slHoriz.Children.Add(vw);

                SuperscriptText ssText = new SuperscriptText()
                {
                    Text = FunctionCalc.MathExpressionAsText(expr.Inputs[1]),       // Not perfect for a complex exponent....
                    //VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center,
                    BackgroundColor = (Color)Application.Current.Resources[App.Key_BackgroundColor],
                    TextColor       = (Color)Application.Current.Resources[App.Key_TextColor],
                };

                ssText.SetBinding(SuperscriptText.FontSizeProperty, new Binding()
                {
                    Source = vw, Path = "FontSize"
                });
                slHoriz.Children.Add(ssText);
            }

            return(stackLayout);
        }