Esempio n. 1
0
        public static View RenderSelectAction(this AdaptiveRenderContext context, AdaptiveAction selectAction, View uiElement)
        {
            if (!context.Config.SupportsInteractivity)
            {
                return(uiElement);
            }
            ContentButton button = (ContentButton)context.Render(selectAction);

            button.HorizontalOptions = LayoutOptions.FillAndExpand;
            button.VerticalOptions   = LayoutOptions.FillAndExpand;
            button.BackgroundColor   = Color.Transparent;
            button.Margin            = 0;
            button.Content           = uiElement;
            button.Style             = context.GetStyle("Adaptive.Action.Tap");
            return(button);
        }
Esempio n. 2
0
        public static View Render(AdaptiveContainer container, AdaptiveRenderContext context)
        {
            ContainerStyleConfig defaultConfig = context.Config.ContainerStyles.Default;
            Grid grid = new Grid()
            {
                Style = context.GetStyle("Adaptive.Container")
            };

            AdaptiveContainerRenderer.AddContainerElements(grid, container.Items, context);
            if (container.SelectAction != null)
            {
                return(context.RenderSelectAction(container.SelectAction, grid));
            }
            Grid grid1 = new Grid()
            {
                BackgroundColor = context.GetColor(defaultConfig.BackgroundColor)
            };

            grid1.Children.Add(grid);
            return(grid1);
        }
Esempio n. 3
0
        public static Label CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            var label1 = new Label()
            {
                Style         = context.GetStyle("Adaptive.TextBlock"),
                LineBreakMode = LineBreakMode.TailTruncation
            };

            switch (textBlock.HorizontalAlignment)
            {
            case AdaptiveHorizontalAlignment.Left:
            {
                label1.HorizontalTextAlignment = TextAlignment.Start;
                break;
            }

            case AdaptiveHorizontalAlignment.Center:
            {
                label1.HorizontalTextAlignment = TextAlignment.Center;
                break;
            }

            case AdaptiveHorizontalAlignment.Right:
            {
                label1.HorizontalTextAlignment = TextAlignment.End;
                break;
            }
            }
            label1.TextColor = context.Resources.TryGetValue <Color>(string.Format("Adaptive.{0}", textBlock.Color));
            if (textBlock.Weight == AdaptiveTextWeight.Bolder)
            {
                label1.FontAttributes = FontAttributes.Bold;
            }
            if (textBlock.Wrap)
            {
                label1.LineBreakMode = LineBreakMode.WordWrap;
            }
            return(label1);
        }
Esempio n. 4
0
        public static View Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            object list;
            string str = input.Value;

            if (str != null)
            {
                list = (
                    from p in str.Split(new char[] { ',' })
                    select p.Trim() into s
                    where !string.IsNullOrEmpty(s)
                    select s).ToList <string>();
            }
            else
            {
                list = null;
            }
            if (list == null)
            {
                list = new List <string>();
            }
            List <string> strs        = (List <string>)list;
            StackLayout   stackLayout = new StackLayout();

            stackLayout.Orientation = StackOrientation.Vertical;
            foreach (AdaptiveChoice choice in input.Choices)
            {
                if (input.IsMultiSelect)
                {
                    var checkBox = new CheckBox()
                    {
                        Text           = choice.Title,
                        IsChecked      = strs.Contains(choice.Value),
                        BindingContext = choice,
                        Style          = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox")
                    };
                    stackLayout.Children.Add(checkBox);


                    checkBox.CheckUnCheckAction = new Action <CheckBox>((c) =>
                    {
                        if (CheckBoxUpdating)
                        {
                            return;
                        }
                        CheckBoxUpdating = true;

                        if (c.Text == "All")
                        {
                            stackLayout.Children.ForEach((i) => (i as CheckBox).IsChecked = c.IsChecked);
                        }
                        else if (c.IsChecked)
                        {
                            CheckBox allCheckBox = null;
                            var isChecked        = true;
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    allCheckBox = box;
                                }
                                else if (!box.IsChecked)
                                {
                                    isChecked = false;
                                    break;
                                }
                            }
                            if (allCheckBox != null && isChecked)
                            {
                                allCheckBox.IsChecked = true;
                            }
                        }
                        else
                        {
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    box.IsChecked = false;
                                    break;
                                }
                            }
                        }
                        CheckBoxUpdating = false;
                    });
                }
            }

            context.HideIcon = true;
            context.InputBindings.Add(input.Id, new Func <string>(() =>
            {
                if (input.IsMultiSelect)
                {
                    string value = string.Empty;
                    foreach (var item in stackLayout.Children)
                    {
                        AdaptiveChoice dataContext = item.BindingContext as AdaptiveChoice;
                        var isChecked = (item as CheckBox).IsChecked;
                        if (!isChecked)//(isChecked.GetValueOrDefault() ? !isChecked.HasValue : true))
                        {
                            continue;
                        }
                        value = string.Concat(value, (value == string.Empty ? "" : ";"), dataContext.Value);
                    }
                    return(value);
                }
                return(string.Empty);
            }));

            return(stackLayout);
        }
Esempio n. 5
0
        public static void AddActions(Grid uiContainer, IList <AdaptiveAction> actions, AdaptiveRenderContext context)
        {
            if (!context.Config.SupportsInteractivity)
            {
                return;
            }

            ActionsConfig         actionsConfig = context.Config.Actions;
            int                   maxActions    = actionsConfig.MaxActions;
            List <AdaptiveAction> list          = actions.Take <AdaptiveAction>(maxActions).ToList <AdaptiveAction>();

            if (!list.Any <AdaptiveAction>())
            {
                return;
            }

            var flexLayout = new FlexLayout()
            {
                JustifyContent = FlexJustify.SpaceEvenly
            };

            if (actionsConfig.ActionsOrientation != ActionsOrientation.Horizontal)
            {
                flexLayout.Direction = FlexDirection.Row;
            }
            else
            {
                flexLayout.Direction = FlexDirection.Column;
            }

            flexLayout.AlignItems = FlexAlignItems.Center;
            flexLayout.Style      = context.GetStyle("Adaptive.Actions");
            flexLayout.Margin     = new Thickness(0, (double)((actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal ? context.Config.GetSpacing(actionsConfig.Spacing) : context.Config.GetSpacing(actionsConfig.Spacing) - actionsConfig.ButtonSpacing)), 0, 0);
            uiContainer.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });

            Grid.SetRow(flexLayout, uiContainer.RowDefinitions.Count - 1);
            uiContainer.Children.Add(flexLayout);
            bool actionMode = actionsConfig.ShowCard.ActionMode == ShowCardActionMode.Inline;

            if (actionMode)
            {
                if (list.Any <AdaptiveAction>((AdaptiveAction a) => a is AdaptiveShowCardAction))
                {
                    uiContainer.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }
            }
            int         num   = 0;
            List <View> views = new List <View>();

            foreach (AdaptiveAction adaptiveAction in list)
            {
                var button = (Button)context.Render(adaptiveAction);
                if (actionsConfig.ActionsOrientation != ActionsOrientation.Horizontal)
                {
                    button.Margin = new Thickness(0, (double)actionsConfig.ButtonSpacing, 0, 0);
                }
                else if (flexLayout.Children.Count > 0)
                {
                    button.Margin = new Thickness((double)actionsConfig.ButtonSpacing, 0, 0, 0);
                }
                if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal)
                {
                    int num1 = num;
                    num = num1 + 1;
                    Grid.SetColumn(button, num1);
                }
                flexLayout.Children.Add(button);
                AdaptiveShowCardAction adaptiveShowCardAction  = adaptiveAction as AdaptiveShowCardAction;
                AdaptiveShowCardAction adaptiveShowCardAction1 = adaptiveShowCardAction;
                if (adaptiveShowCardAction == null || !actionMode)
                {
                    continue;
                }
                var grid = new Grid()
                {
                    Style          = context.GetStyle("Adaptive.Actions.ShowCard"),
                    BindingContext = adaptiveShowCardAction1,
                    Margin         = new Thickness(0, (double)actionsConfig.ShowCard.InlineTopMargin, 0, 0),
                    IsVisible      = false
                };

                var showCardGrid = (Grid)context.Render(adaptiveShowCardAction1.Card);
                showCardGrid.BackgroundColor    = Color.Transparent;
                showCardGrid.BindingContext     = adaptiveShowCardAction1;
                showCardGrid.Children[0].Margin = new Thickness(0);

                grid.Children.Add(showCardGrid);
                views.Add(grid);
                Grid.SetRow(grid, uiContainer.RowDefinitions.Count - 1);
                uiContainer.Children.Add(grid);

                button.Clicked += new EventHandler((object sender, EventArgs e) =>
                {
                    foreach (var actionBarCard in views)
                    {
                        actionBarCard.IsVisible = false;
                    }
                    if (!grid.IsVisible)
                    {
                        grid.IsVisible = true;
                    }
                });
            }
        }