Esempio n. 1
0
        private void RenderElements(Grid grid)
        {
            //First clear all existing rendered elements.
            if (renderedElements.Count > 0)
            {
                foreach (var renderedElement in renderedElements)
                {
                    grid.Children.Remove(renderedElement);
                }
            }

            foreach (var valModel in UiPropertyMapping)
            {
                if (valModel.ValidationResult?.Count == 0)
                {
                    continue;
                }

                var   view = valModel.UiElement;
                Entry uiElement;
                try
                {
                    uiElement = (Entry)view;
                }
                catch (InvalidCastException)
                {
                    throw new Exception("Only Entry is supported for input validation.");
                }

                uiElement.Focused += delegate
                {
                    MessagingCenter.Send <View>(grid, "Clear_FloatingText");

                    if (valModel.ValidationResult?.Count == 0)
                    {
                        return;
                    }

                    var bubble = new FloatingText(grid)
                    {
                        TranslationX = uiElement.X + uiElement.Width,
                        TranslationY = uiElement.Y + uiElement.Height - 4
                    };
                    bubble.FindByName <Label>("InfoText").Text = valModel.ValidationResult[0];

                    grid.Children.Add(bubble, 0, 0);
                };

                var label = new Label()
                {
                    Text              = "❗",
                    TextColor         = Color.Red,
                    VerticalOptions   = LayoutOptions.Start,
                    HorizontalOptions = LayoutOptions.Start,
                    TranslationX      = (uiElement.X + uiElement.Width) - 20,
                    TranslationY      = uiElement.Y + 10
                };
                grid.Children.Add(label, 0, 0);

                renderedElements.Add(label);
            }
        }