Esempio n. 1
0
 public static FrameworkElement Render(AdaptiveTimeInput input, AdaptiveRenderContext context)
 {
     if (context.Config.SupportsInteractivity)
     {
         var      timePicker = new TimePicker();
         DateTime value;
         if (IsSupportedTimeFormat(input.Value) && DateTime.TryParse(input.Value, out value))
         {
             timePicker.Value = value;
         }
         TimeSpan minValue;
         if (IsSupportedTimeFormat(input.Min) && TimeSpan.TryParse(input.Min, out minValue))
         {
             timePicker.EndTime = minValue;
         }
         TimeSpan maxValue;
         if (IsSupportedTimeFormat(input.Max) && TimeSpan.TryParse(input.Max, out maxValue))
         {
             timePicker.EndTime = maxValue;
         }
         timePicker.Watermark   = input.Placeholder;
         timePicker.Style       = context.GetStyle("Adaptive.Input.Time");
         timePicker.DataContext = input;
         context.InputBindings.Add(input.Id, () => ToIso8601Time(timePicker.Text));
         return(timePicker);
     }
     else
     {
         var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
         textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
         return(context.Render(textBlock));
     }
 }
        public static FrameworkElement Render(AdaptiveNumberInput input, AdaptiveRenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                IntegerUpDown numberPicker = new IntegerUpDown();
                // numberPicker.ShowButtonSpinner = true;

                if (!Double.IsNaN(input.Value))
                {
                    numberPicker.Value = Convert.ToInt32(input.Value);
                }

                if (!Double.IsNaN(input.Min))
                {
                    numberPicker.Minimum = Convert.ToInt32(input.Min);
                }

                if (!Double.IsNaN(input.Max))
                {
                    numberPicker.Minimum = Convert.ToInt32(input.Max);
                }

                numberPicker.Watermark   = input.Placeholder;
                numberPicker.Style       = context.GetStyle("Adaptive.Input.Number");
                numberPicker.DataContext = input;
                context.InputBindings.Add(input.Id, () => numberPicker.Value?.ToString());
                return(numberPicker);
            }
            else
            {
                var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
        public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderContext context)
        {
            var textBox = new TextBox()
            {
                Text = input.Value
            };

            if (input.IsMultiline == true)
            {
                textBox.AcceptsReturn = true;

                textBox.TextWrapping = TextWrapping.Wrap;
                textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
            }

            if (input.MaxLength > 0)
            {
                textBox.MaxLength = input.MaxLength;
            }

            textBox.SetPlaceholder(input.Placeholder);
            textBox.Style = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
            textBox.SetContext(input);
            context.InputBindings.Add(input.Id, () => textBox.Text);
            return(textBox);
        }
        public static FrameworkElement Render(AdaptiveColumn column, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            uiContainer.Style = context.GetStyle("Adaptive.Column");

            AdaptiveContainerRenderer.AddContainerElements(uiContainer, column.Items, context);

            if (column.SelectAction != null)
            {
                return(context.RenderSelectAction(column.SelectAction, uiContainer));
            }

            switch (column.VerticalContentAlignment)
            {
            case AdaptiveVerticalContentAlignment.Center:
                uiContainer.VerticalAlignment = VerticalAlignment.Center;
                break;

            case AdaptiveVerticalContentAlignment.Bottom:
                uiContainer.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            case AdaptiveVerticalContentAlignment.Top:
            default:
                break;
            }

            return(uiContainer);
        }
Esempio n. 5
0
 public static FrameworkElement Render(AdaptiveDateInput input, AdaptiveRenderContext context)
 {
     if (context.Config.SupportsInteractivity)
     {
         var datePicker = new DatePicker();
         datePicker.ToolTip = input.Placeholder;
         DateTime value;
         if (DateTime.TryParse(input.Value, out value))
         {
             datePicker.SelectedDate = value;
         }
         DateTime minValue;
         if (DateTime.TryParse(input.Min, out minValue))
         {
             datePicker.DisplayDateStart = minValue;
         }
         DateTime maxValue;
         if (DateTime.TryParse(input.Max, out maxValue))
         {
             datePicker.DisplayDateEnd = maxValue;
         }
         datePicker.Style       = context.GetStyle("Adaptive.Input.Date");
         datePicker.DataContext = input;
         context.InputBindings.Add(input.Id, () => ToIso8601Date(datePicker.Text));
         return(datePicker);
     }
     else
     {
         var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
         textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
         return(context.Render(textBlock));
     }
 }
        public static void AddSeparator(AdaptiveRenderContext context, AdaptiveElement element, Grid uiContainer)
        {
            if (element.Spacing == AdaptiveSpacing.None && !element.Separator)
            {
                return;
            }

            var uiSep = new Grid();

            uiSep.Style = context.GetStyle($"Adaptive.Separator");
            int spacing = context.Config.GetSpacing(element.Spacing);

            SeparatorConfig sepStyle = context.Config.Separator;

            uiSep.Margin = new Thickness(0, (spacing - sepStyle.LineThickness) / 2, 0, 0);
            uiSep.SetHeight(sepStyle.LineThickness);
            if (!string.IsNullOrWhiteSpace(sepStyle.LineColor))
            {
                uiSep.SetBackgroundColor(sepStyle.LineColor, context);
            }
            uiContainer.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            Grid.SetRow(uiSep, uiContainer.RowDefinitions.Count - 1);
            uiContainer.Children.Add(uiSep);
        }
        public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            //uiContainer.Margin = new Thickness(context.Config.Spacing.Padding);
            uiContainer.Style = context.GetStyle("Adaptive.Container");

            if (container.Style != null)
            {
                // Apply background color
                var containerStyle = context.Config.ContainerStyles.Default;
                if (container.Style == AdaptiveContainerStyle.Emphasis)
                {
                    containerStyle = context.Config.ContainerStyles.Emphasis;
                }

                uiContainer.SetBackgroundColor(containerStyle.BackgroundColor, context);
            }

            AddContainerElements(uiContainer, container.Items, context);

            if (container.SelectAction != null)
            {
                return(context.RenderSelectAction(container.SelectAction, uiContainer));
            }

            Grid uiOuterContainer = new Grid();

            uiOuterContainer.Children.Add(uiContainer);
            Border border = new Border();

            border.Child = uiOuterContainer;
            return(border);
        }
 public static FrameworkElement Render(AdaptiveTimeInput input, AdaptiveRenderContext context)
 {
     if (context.Config.SupportsInteractivity)
     {
         var textBox = new TextBox()
         {
             Text = input.Value
         };
         textBox.SetPlaceholder(input.Placeholder);
         textBox.Style = context.GetStyle($"Adaptive.Input.Text.Time");
         textBox.SetContext(input);
         context.InputBindings.Add(input.Id, () => textBox.Text);
         return(textBox);
     }
     else
     {
         AdaptiveContainer container = AdaptiveTypedElementConverter.CreateElement <AdaptiveContainer>();
         container.Spacing   = input.Spacing;
         container.Separator = input.Separator;
         AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
         textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
         container.Items.Add(textBlock);
         if (input.Value != null)
         {
             textBlock       = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
             textBlock.Text  = input.Value;
             textBlock.Color = AdaptiveTextColor.Accent;
             textBlock.Wrap  = true;
             container.Items.Add(textBlock);
         }
         return(context.Render(container));
     }
 }
Esempio n. 9
0
        public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext context)
        {
            var containerStyle = context.Config.ContainerStyles.Default;
            var uiContainer    = new Grid();

            //uiContainer.Margin = new Thickness(context.Config.Spacing.Padding);
            uiContainer.Style = context.GetStyle("Adaptive.Container");
            AddContainerElements(uiContainer, container.Items, context);

            if (container.SelectAction != null)
            {
                var uiButton = (Button)context.Render(container.SelectAction);
                if (uiButton != null)
                {
                    uiButton.Content = uiContainer;
                    uiButton.Style   = context.GetStyle("Adaptive.Action.Tap");
                    return(uiButton);
                }
            }

            Grid uiOuterContainer = new Grid();

            uiOuterContainer.Background = context.GetColorBrush(containerStyle.BackgroundColor);
            uiOuterContainer.Children.Add(uiContainer);
            Border border = new Border();

            border.Child = uiOuterContainer;
            return(border);
        }
Esempio n. 10
0
        public static Button CreateActionButton(AdaptiveAction action, AdaptiveRenderContext context)
        {
            ActionsConfig styling  = context.Config.Actions;
            var           uiButton = new Button()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
            };

            uiButton.SetBackgroundColor(styling.BackgroundColor, context);
            uiButton.SetBorderColor(styling.BorderColor, context);
            uiButton.SetBorderThickness(styling.BorderThickness);
            uiButton.Style = context.GetStyle($"Adaptive.{action.Type}");

            TextBlock uiTitle = new TextBlock()
            {
                Text     = action.Title,
                FontSize = styling.FontSize,
                Margin   = new Thickness(6)
                           // TODO: Should this be from HostConfig?
            };

            uiTitle.SetFontWeight(styling.FontWeight);
            uiTitle.SetColor(styling.TextColor, context);
            uiTitle.Style    = context.GetStyle($"Adaptive.Action.Title");
            uiButton.Content = uiTitle;
            string name = context.GetType().Name.Replace("Action", String.Empty);

            return(uiButton);
        }
        public static FrameworkElement Render(AdaptiveImage image, AdaptiveRenderContext context)
        {
            var uiImage = new Image();

            uiImage.SetSource(image.Url, context);
            uiImage.SetHorizontalAlignment(image.HorizontalAlignment);

            string style = $"Adaptive.{image.Type}";

            if (image.Style == AdaptiveImageStyle.Person)
            {
                style += $".{image.Style}";

                var mask = new RadialGradientBrush()
                {
                    GradientOrigin = new Point(0.5, 0.5),
                    Center         = new Point(0.5, 0.5),
                    RadiusX        = 0.5,
                    RadiusY        = 0.5,
                    GradientStops  = new GradientStopCollection()
                };
                mask.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#ffffffff"), .9));
                mask.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#00ffffff"), 1.0));
                uiImage.OpacityMask = mask;
            }
            uiImage.Style = context.GetStyle(style);
            uiImage.SetImageProperties(image, context);

            if (image.SelectAction != null)
            {
                return(context.RenderSelectAction(image.SelectAction, uiImage));
            }
            return(uiImage);
        }
        private static Inline FormatInlineTextRun(AdaptiveTextRun textRun, AdaptiveRenderContext context)
        {
            Marked marked = new Marked();

            marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer();
            marked.Options.Mangle   = false;
            marked.Options.Sanitize = true;

            // Handle Date/Time parsing
            string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang);

            // Handle markdown
            string       xaml         = $"<Span  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"  xml:space=\"preserve\">{marked.Parse(text)}</Span>";
            StringReader stringReader = new StringReader(xaml);
            XmlReader    xmlReader    = XmlReader.Create(stringReader);

            Span uiInlineElement = XamlReader.Load(xmlReader) as Span;

            uiInlineElement.Style = context.GetStyle($"Adaptive.{textRun.Type}");

            uiInlineElement.FontFamily = new FontFamily(context.Config.GetFontFamily(textRun.FontStyle));
            uiInlineElement.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontStyle, textRun.Weight));
            uiInlineElement.FontSize   = context.Config.GetFontSize(textRun.FontStyle, textRun.Size);

            uiInlineElement.SetColor(textRun.Color, textRun.IsSubtle, context);

            return(uiInlineElement);
        }
        public static FrameworkElement Render(AdaptiveImageSet imageSet, AdaptiveRenderContext context)
        {
            var uiImageSet = new ListBox();

            uiImageSet.BorderThickness = new Thickness(0);
            uiImageSet.Background      = new SolidColorBrush(Colors.Transparent);
            ScrollViewer.SetHorizontalScrollBarVisibility(uiImageSet, ScrollBarVisibility.Disabled);
            var itemsPanelTemplate = new ItemsPanelTemplate();
            var factory            = new FrameworkElementFactory(typeof(WrapPanel));

            // factory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            itemsPanelTemplate.VisualTree = factory;
            uiImageSet.ItemsPanel         = itemsPanelTemplate;

            uiImageSet.Style = context.GetStyle("Adaptive.ImageSet");
            foreach (var image in imageSet.Images)
            {
                if (image.Size == AdaptiveImageSize.Auto)
                {
                    if (imageSet.ImageSize != AdaptiveImageSize.Auto)
                    {
                        image.Size = imageSet.ImageSize;
                    }
                    else
                    {
                        image.Size = context.Config.ImageSet.ImageSize;
                    }
                }

                var uiImage = context.Render(image);
                uiImageSet.Add(uiImage);
            }
            return(uiImageSet);
        }
Esempio n. 14
0
        public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                var textBox = new WatermarkTextBox()
                {
                    Text = input.Value
                };
                if (input.IsMultiline == true)
                {
                    textBox.AcceptsReturn = true;
                    textBox.TextWrapping  = TextWrapping.Wrap;
                    textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
                }
                if (input.MaxLength > 0)
                {
                    textBox.MaxLength = input.MaxLength;
                }

                textBox.Watermark   = input.Placeholder;
                textBox.Style       = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
                textBox.DataContext = input;
                context.InputBindings.Add(input.Id, () => textBox.Text);
                return(textBox);
            }
            else
            {
                var textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
Esempio n. 15
0
        public static FrameworkElement Render(AdaptiveToggleInput input, AdaptiveRenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                var uiToggle = new CheckBox();

                uiToggle.Content = input.Title;
                uiToggle.SetState(input.Value == (input.ValueOn ?? "true"));
                uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle");
                uiToggle.SetContext(input);
                context.InputBindings.Add(input.Id, () => uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false");
                return(uiToggle);
            }
            else
            {
                AdaptiveContainer container = AdaptiveTypedElementConverter.CreateElement <AdaptiveContainer>();
                container.Spacing   = input.Spacing;
                container.Separator = input.Separator;

                AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input);
                container.Items.Add(textBlock);
                if (input.Value != null)
                {
                    textBlock       = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                    textBlock.Text  = (input.Value == (input.ValueOn ?? "true")) ? input.ValueOn ?? "selected" : input.ValueOff ?? "not selected";
                    textBlock.Color = AdaptiveTextColor.Accent;
                    textBlock.Wrap  = true;
                    container.Items.Add(textBlock);
                }
                return(context.Render(container));
            }
        }
Esempio n. 16
0
        public static FrameworkElement Render(AdaptiveFactSet factSet, AdaptiveRenderContext context)
        {
            var uiFactSet = new Grid();

            // grid.Margin = factSet.Theme.FactSetMargins;
            uiFactSet.Style = context.GetStyle("Adaptive.FactSet");

            uiFactSet.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            uiFactSet.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
            int iRow = 0;

            foreach (var fact in factSet.Facts)
            {
                var uiTitle = context.Render(new AdaptiveTextBlock()
                {
                    Size     = context.Config.FactSet.Title.Size,
                    Color    = context.Config.FactSet.Title.Color,
                    IsSubtle = context.Config.FactSet.Title.IsSubtle,
                    Weight   = context.Config.FactSet.Title.Weight,
                    Wrap     = context.Config.FactSet.Title.Wrap,
                    Text     = fact.Title
                });

                uiTitle.Style  = context.GetStyle("Adaptive.Fact.Title");
                uiTitle.Margin = new Thickness(left: 0, top: 0, right: context.Config.FactSet.Spacing, bottom: 0);

                var uiValue = context.Render(new AdaptiveTextBlock()
                {
                    Size     = context.Config.FactSet.Value.Size,
                    Color    = context.Config.FactSet.Value.Color,
                    IsSubtle = context.Config.FactSet.Value.IsSubtle,
                    Weight   = context.Config.FactSet.Value.Weight,
                    Wrap     = context.Config.FactSet.Value.Wrap,
                    Text     = fact.Value
                });

                uiValue.Style = context.GetStyle("Adaptive.Fact.Value");

                uiFactSet.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });

                Grid.SetColumn(uiTitle, 0);
                Grid.SetRow(uiTitle, iRow);
                uiFactSet.Children.Add(uiTitle);

                Grid.SetColumn(uiValue, 1);
                Grid.SetRow(uiValue, iRow++);
                uiFactSet.Children.Add(uiValue);
            }
            return(uiFactSet);
        }
Esempio n. 17
0
 public static void SetSource(this Image image, Uri url, AdaptiveRenderContext context)
 {
     if (url == null)
     {
         return;
     }
     image.Source = context.ResolveImageSource(url);
 }
        public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            //uiContainer.Margin = new Thickness(context.Config.Spacing.Padding);
            uiContainer.Style = context.GetStyle("Adaptive.Container");
            uiContainer.SetBackgroundSource(container.BackgroundImage, context);

            // Keep track of ContainerStyle.ForegroundColors before Container is rendered
            var outerStyle = context.ForegroundColors;

            if (container.Style != null)
            {
                // Apply background color
                ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(container.Style);
                uiContainer.SetBackgroundColor(containerStyle.BackgroundColor, context);

                context.ForegroundColors = containerStyle.ForegroundColors;
            }

            switch (container.VerticalContentAlignment)
            {
            case AdaptiveVerticalContentAlignment.Center:
                uiContainer.VerticalAlignment = VerticalAlignment.Center;
                break;

            case AdaptiveVerticalContentAlignment.Bottom:
                uiContainer.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            case AdaptiveVerticalContentAlignment.Top:
            default:
                break;
            }

            AddContainerElements(uiContainer, container.Items, context);

            if (container.SelectAction != null)
            {
                return(context.RenderSelectAction(container.SelectAction, uiContainer));
            }

            Grid uiOuterContainer = new Grid();

            uiOuterContainer.Children.Add(uiContainer);
            Border border = new Border();

            border.Child = uiOuterContainer;

            if (!container.IsVisible)
            {
                border.Visibility = Visibility.Collapsed;
            }

            // Revert context's value to that of outside the Container
            context.ForegroundColors = outerStyle;
            return(border);
        }
Esempio n. 19
0
        public static FrameworkElement Render(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            var uiTextBlock = CreateControl(textBlock, context);

            uiTextBlock.SetColor(textBlock.Color, textBlock.IsSubtle, context);

            if (textBlock.MaxWidth > 0)
            {
                uiTextBlock.MaxWidth = textBlock.MaxWidth;
            }

            if (textBlock.MaxLines > 0)
            {
                var uiGrid = new Grid();
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });

                // create hidden textBlock with appropriate linebreaks that we can use to measure the ActualHeight
                // using same style, fontWeight settings as original textblock
                var measureBlock = new TextBlock()
                {
                    Style               = uiTextBlock.Style,
                    FontWeight          = uiTextBlock.FontWeight,
                    FontSize            = uiTextBlock.FontSize,
                    Visibility          = Visibility.Hidden,
                    TextWrapping        = TextWrapping.NoWrap,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    DataContext         = textBlock.MaxLines
                };

                measureBlock.Inlines.Add(uiTextBlock.Text);

                // bind the real textBlock's Height => MeasureBlock.ActualHeight
                uiTextBlock.SetBinding(FrameworkElement.MaxHeightProperty, new Binding()
                {
                    Path      = new PropertyPath("ActualHeight"),
                    Source    = measureBlock,
                    Mode      = BindingMode.OneWay,
                    Converter = new MultiplyConverter(textBlock.MaxLines)
                });

                // Add both to a grid so they go as a unit
                uiGrid.Children.Add(measureBlock);

                uiGrid.Children.Add(uiTextBlock);
                return(uiGrid);
            }

            if (!textBlock.IsVisible)
            {
                uiTextBlock.Visibility = Visibility.Collapsed;
            }

            return(uiTextBlock);
        }
        public static FrameworkElement Render(AdaptiveContainer container, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            //uiContainer.Margin = new Thickness(context.Config.Spacing.Padding);
            uiContainer.Style = context.GetStyle("Adaptive.Container");
            uiContainer.SetBackgroundSource(container.BackgroundImage, context);

            if (container.Style != null)
            {
                // Apply background color
                var containerStyle = context.Config.ContainerStyles.Default;
                if (container.Style == AdaptiveContainerStyle.Emphasis)
                {
                    containerStyle = context.Config.ContainerStyles.Emphasis;
                }

                uiContainer.SetBackgroundColor(containerStyle.BackgroundColor, context);
            }

            switch (container.VerticalContentAlignment)
            {
            case AdaptiveVerticalContentAlignment.Center:
                uiContainer.VerticalAlignment = VerticalAlignment.Center;
                break;

            case AdaptiveVerticalContentAlignment.Bottom:
                uiContainer.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            case AdaptiveVerticalContentAlignment.Top:
            default:
                break;
            }

            AddContainerElements(uiContainer, container.Items, context);

            if (container.SelectAction != null)
            {
                return(context.RenderSelectAction(container.SelectAction, uiContainer));
            }

            Grid uiOuterContainer = new Grid();

            uiOuterContainer.Children.Add(uiContainer);
            Border border = new Border();

            border.Child = uiOuterContainer;

            if (!container.IsVisible)
            {
                border.Visibility = Visibility.Collapsed;
            }

            return(border);
        }
Esempio n. 21
0
        private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            Marked marked = new Marked();

            marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer();
            marked.Options.Mangle   = false;
            marked.Options.Sanitize = true;

            string text = RendererUtilities.ApplyTextFunctions(textBlock.Text);
            // uiTextBlock.Text = textBlock.Text;
            string       xaml         = $"<TextBlock  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>";
            StringReader stringReader = new StringReader(xaml);

            XmlReader xmlReader   = XmlReader.Create(stringReader);
            var       uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader);

            uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}");

            uiTextBlock.FontFamily   = new FontFamily(context.Config.FontFamily);
            uiTextBlock.TextWrapping = TextWrapping.NoWrap;

            switch (textBlock.Weight)
            {
            case AdaptiveTextWeight.Bolder:
                uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(700);
                break;

            case AdaptiveTextWeight.Lighter:
                uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(300);
                break;

            case AdaptiveTextWeight.Default:
            default:
                uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(400);
                break;
            }

            uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis;

            if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left)
            {
                System.Windows.HorizontalAlignment alignment;
                if (Enum.TryParse <System.Windows.HorizontalAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment))
                {
                    uiTextBlock.HorizontalAlignment = alignment;
                }
            }

            if (textBlock.Wrap)
            {
                uiTextBlock.TextWrapping = TextWrapping.Wrap;
            }

            return(uiTextBlock);
        }
        public static FrameworkElement Render(AdaptiveAction action, AdaptiveRenderContext context)
        {
            if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(action.GetType()))
            {
                var uiButton = CreateActionButton(action, context);
                uiButton.Click += (sender, e) =>
                {
                    if (action is AdaptiveToggleVisibilityAction toggleVisibilityAction)
                    {
                        foreach (object targetElement in toggleVisibilityAction.TargetElements)
                        {
                            string targetElementId        = "";
                            bool?  targetElementIsVisible = null;

                            if (targetElement is string targetElementString)
                            {
                                targetElementId = targetElementString;
                            }
                            else if (targetElement is AdaptiveTargetElement targetElementObject)
                            {
                                targetElementId        = targetElementObject.ElementId;
                                targetElementIsVisible = targetElementObject.IsVisible;
                            }

                            var element = LogicalTreeHelper.FindLogicalNode(context.CardRoot, targetElementId);

                            if (element != null && element is FrameworkElement elementFrameworkElement)
                            {
                                Visibility visibility = elementFrameworkElement.Visibility;
                                // if we read something with the format {"elementId": <id>", "isVisible": true} or we just read the id and the element is not visible
                                if ((targetElementIsVisible.HasValue && targetElementIsVisible.Value) || (!targetElementIsVisible.HasValue && visibility != Visibility.Visible))
                                {
                                    elementFrameworkElement.Visibility = Visibility.Visible;
                                }
                                // otherwise if we read something with the format {"elementId": <id>", "isVisible": false} or we just read the id and the element is visible
                                else if ((targetElementIsVisible.HasValue && !targetElementIsVisible.Value) || (!targetElementIsVisible.HasValue && visibility == Visibility.Visible))
                                {
                                    elementFrameworkElement.Visibility = Visibility.Collapsed;
                                }
                            }
                        }
                    }
                    else
                    {
                        context.InvokeAction(uiButton, new AdaptiveActionEventArgs(action));
                    }

                    // Prevent nested events from triggering
                    e.Handled = true;
                };
                return(uiButton);
            }
            return(null);
        }
        public static FrameworkElement Render(AdaptiveColumn column, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            uiContainer.Style = context.GetStyle("Adaptive.Column");
            uiContainer.SetBackgroundSource(column.BackgroundImage, context);

            // Keep track of ContainerStyle.ForegroundColors before Container is rendered
            var parentRenderArgs = context.RenderArgs;
            // This is the renderArgs that will be passed down to the children
            var childRenderArgs = new AdaptiveRenderArgs(parentRenderArgs);

            Border border = new Border();

            border.Child = uiContainer;

            bool inheritsStyleFromParent = !column.Style.HasValue;
            bool columnHasPadding        = false;

            if (!inheritsStyleFromParent)
            {
                columnHasPadding = AdaptiveContainerRenderer.ApplyPadding(border, uiContainer, column, parentRenderArgs, context);

                // Apply background color
                ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(column.Style);
                border.Background = context.GetColorBrush(containerStyle.BackgroundColor);

                childRenderArgs.ForegroundColors = containerStyle.ForegroundColors;
            }

            childRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : column.Style.Value;

            // If the column has no padding or has padding and doesn't bleed, then the children can bleed
            // to the side the column would have bled
            if (columnHasPadding)
            {
                childRenderArgs.BleedDirection = BleedDirection.Both;
            }

            // If either this column or an ancestor had padding, then the children will have an ancestor with padding
            childRenderArgs.HasParentWithPadding = (columnHasPadding || parentRenderArgs.HasParentWithPadding);
            context.RenderArgs = childRenderArgs;

            AdaptiveContainerRenderer.AddContainerElements(uiContainer, column.Items, context);

            RendererUtil.ApplyVerticalContentAlignment(uiContainer, column);
            RendererUtil.ApplyIsVisible(uiContainer, column);
            uiContainer.MinHeight = column.PixelMinHeight;

            // Revert context's value to that of outside the Column
            context.RenderArgs = parentRenderArgs;

            return(RendererUtil.ApplySelectAction(border, column, context));
        }
Esempio n. 24
0
        public static FrameworkElement Render(AdaptiveRichTextBlock richTB, AdaptiveRenderContext context)
        {
            var uiRichTB = CreateControl(richTB, context);

            foreach (var inlineElement in richTB.Inlines)
            {
                AdaptiveTextRun textRun = inlineElement as AdaptiveTextRun;
                AddInlineTextRun(uiRichTB, textRun, context);
            }

            return(uiRichTB);
        }
Esempio n. 25
0
        private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            Marked marked = new Marked();

            marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer();
            marked.Options.Mangle   = false;
            marked.Options.Sanitize = true;

            string text = RendererUtilities.ApplyTextFunctions(textBlock.Text, context.Lang);
            // uiTextBlock.Text = textBlock.Text;
            string       xaml         = $"<TextBlock  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>";
            StringReader stringReader = new StringReader(xaml);

            XmlReader xmlReader   = XmlReader.Create(stringReader);
            var       uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader);

            uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}");

            uiTextBlock.TextWrapping = TextWrapping.NoWrap;

            uiTextBlock.FontFamily = new FontFamily(RendererUtil.GetFontFamilyFromList(context.Config.GetFontFamily(textBlock.FontType)));
            uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textBlock.FontType, textBlock.Weight));
            uiTextBlock.FontSize   = context.Config.GetFontSize(textBlock.FontType, textBlock.Size);

            uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis;

            if (textBlock.Italic)
            {
                uiTextBlock.FontStyle = FontStyles.Italic;
            }

            if (textBlock.Strikethrough)
            {
                uiTextBlock.TextDecorations = TextDecorations.Strikethrough;
            }

            if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left)
            {
                System.Windows.TextAlignment alignment;
                if (Enum.TryParse <System.Windows.TextAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment))
                {
                    uiTextBlock.TextAlignment = alignment;
                }
            }

            if (textBlock.Wrap)
            {
                uiTextBlock.TextWrapping = TextWrapping.Wrap;
            }

            return(uiTextBlock);
        }
Esempio n. 26
0
        public static FrameworkElement Render(AdaptiveToggleInput input, AdaptiveRenderContext context)
        {
            var uiToggle = new CheckBox();

            uiToggle.Content    = input.Title;
            uiToggle.Foreground =
                context.GetColorBrush(context.Config.ContainerStyles.Default.ForegroundColors.Default.Default);
            uiToggle.SetState(input.Value == (input.ValueOn ?? "true"));
            uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle");
            uiToggle.SetContext(input);
            context.InputBindings.Add(input.Id, () => uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false");
            return(uiToggle);
        }
Esempio n. 27
0
 public static void SetBackgroundSource(this Grid grid, Uri url, AdaptiveRenderContext context)
 {
     if (url == null)
     {
         return;
     }
     grid.Background = new ImageBrush(context.ResolveImageSource(url))
     {
         Stretch    = Stretch.UniformToFill,
         AlignmentX = AlignmentX.Left,
         AlignmentY = AlignmentY.Top
     };
 }
Esempio n. 28
0
        public static FrameworkElement Render(AdaptiveNumberInput input, AdaptiveRenderContext context)
        {
            var textBox = new TextBox()
            {
                Text = input.Value.ToString()
            };

            textBox.SetPlaceholder(input.Placeholder);
            textBox.Style = context.GetStyle($"Adaptive.Input.Text.Number");
            textBox.SetContext(input);
            context.InputBindings.Add(input.Id, () => textBox.Text);
            return(textBox);
        }
 public static FrameworkElement Render(AdaptiveAction action, AdaptiveRenderContext context)
 {
     if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(action.GetType()))
     {
         var uiButton = CreateActionButton(action, context);
         uiButton.Click += (sender, e) =>
         {
             context.InvokeAction(uiButton, new AdaptiveActionEventArgs(action));
         };
         return(uiButton);
     }
     return(null);
 }
        public static FrameworkElement Render(AdaptiveColumn column, AdaptiveRenderContext context)
        {
            var uiContainer = new Grid();

            uiContainer.Style = context.GetStyle("Adaptive.Column");
            uiContainer.SetBackgroundSource(column.BackgroundImage, context);

            // Keep track of ContainerStyle.ForegroundColors before Container is rendered
            var parentRenderArgs  = context.RenderArgs;
            var elementRenderArgs = new AdaptiveRenderArgs(parentRenderArgs);

            Border border = new Border();

            border.Child = uiContainer;

            bool inheritsStyleFromParent = !column.Style.HasValue;
            bool columnHasPadding        = false;

            if (!inheritsStyleFromParent)
            {
                columnHasPadding = AdaptiveContainerRenderer.ApplyPadding(border, uiContainer, column, parentRenderArgs, context);

                // Apply background color
                ContainerStyleConfig containerStyle = context.Config.ContainerStyles.GetContainerStyleConfig(column.Style);
                border.Background = context.GetColorBrush(containerStyle.BackgroundColor);

                elementRenderArgs.ForegroundColors = containerStyle.ForegroundColors;
            }

            elementRenderArgs.ParentStyle = (inheritsStyleFromParent) ? parentRenderArgs.ParentStyle : column.Style.Value;
            if ((parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.Begin) ||
                (parentRenderArgs.ColumnRelativePosition == ColumnPositionEnum.End))
            {
                elementRenderArgs.ColumnRelativePosition = ColumnPositionEnum.Intermediate;
            }

            elementRenderArgs.HasParentWithPadding = columnHasPadding;
            context.RenderArgs = elementRenderArgs;

            AdaptiveContainerRenderer.AddContainerElements(uiContainer, column.Items, context);

            RendererUtil.ApplyVerticalContentAlignment(uiContainer, column);
            RendererUtil.ApplyIsVisible(uiContainer, column);
            uiContainer.MinHeight = column.PixelMinHeight;

            // Revert context's value to that of outside the Column
            context.RenderArgs = parentRenderArgs;

            return(RendererUtil.ApplySelectAction(border, column, context));
        }