예제 #1
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 Button CreateActionButton(AdaptiveAction action, AdaptiveRenderContext context)
        {
            var uiButton = new Button
            {
                //HorizontalAlignment = HorizontalAlignment.Stretch,
                Style   = context.GetStyle($"Adaptive.{action.Type}"),
                Padding = new Thickness(6, 4, 6, 4),
                Content = new TextBlock
                {
                    Text     = action.Title,
                    FontSize = context.Config.FontSizes.Default,
                    Style    = context.GetStyle($"Adaptive.Action.Title")
                }
            };

            string name = context.GetType().Name.Replace("Action", String.Empty);

            return(uiButton);
        }
        public static Button CreateActionButton(AdaptiveAction action, AdaptiveRenderContext context)
        {
            var uiButton = new Button
            {
                Style = context.GetStyle($"Adaptive.{action.Type}"),
            };

            if (action.Sentiment == AdaptiveSentiment.Positive || action.Sentiment == AdaptiveSentiment.Destructive)
            {
                Style sentimentStyle = context.GetStyle($"Adaptive.{action.Type}.{action.Sentiment}");

                if (sentimentStyle == null)
                {
                    if (action.Sentiment == AdaptiveSentiment.Positive)
                    {
                        sentimentStyle = context.GetStyle("PositiveActionDefaultStyle");
                    }
                    else if (action.Sentiment == AdaptiveSentiment.Destructive)
                    {
                        sentimentStyle = context.GetStyle("DestructiveActionDefaultStyle");
                    }
                }

                uiButton.Style = sentimentStyle;
            }

            var contentStackPanel = new StackPanel();

            if (!context.IsRenderingSelectAction)
            {
                // Only apply padding for normal card actions
                uiButton.Padding = new Thickness(6, 4, 6, 4);
            }
            else
            {
                // Remove any extra spacing for selectAction
                uiButton.Padding         = new Thickness(0, 0, 0, 0);
                contentStackPanel.Margin = new Thickness(0, 0, 0, 0);
            }
            uiButton.Content = contentStackPanel;
            FrameworkElement uiIcon = null;

            var uiTitle = new TextBlock
            {
                Text     = action.Title,
                FontSize = context.Config.GetFontSize(AdaptiveFontStyle.Default, AdaptiveTextSize.Default),
                Style    = context.GetStyle($"Adaptive.Action.Title")
            };

            if (action.IconUrl != null)
            {
                var actionsConfig = context.Config.Actions;

                var image = new AdaptiveImage(action.IconUrl)
                {
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                };
                uiIcon = AdaptiveImageRenderer.Render(image, context);
                if (actionsConfig.IconPlacement == IconPlacement.AboveTitle)
                {
                    contentStackPanel.Orientation = Orientation.Vertical;
                    uiIcon.Height = (double)actionsConfig.IconSize;
                }
                else
                {
                    contentStackPanel.Orientation = Orientation.Horizontal;
                    //Size the image to the textblock, wait until layout is complete (loaded event)
                    uiIcon.Loaded += (sender, e) =>
                    {
                        uiIcon.Height = uiTitle.ActualHeight;
                    };
                }
                contentStackPanel.Children.Add(uiIcon);

                // Add spacing for the icon for horizontal actions
                if (actionsConfig.IconPlacement == IconPlacement.LeftOfTitle)
                {
                    int spacing = context.Config.GetSpacing(AdaptiveSpacing.Default);
                    var uiSep   = new Grid
                    {
                        Style             = context.GetStyle($"Adaptive.VerticalSeparator"),
                        VerticalAlignment = VerticalAlignment.Stretch,
                        Width             = spacing,
                    };
                    contentStackPanel.Children.Add(uiSep);
                }
            }

            contentStackPanel.Children.Add(uiTitle);

            string name = context.GetType().Name.Replace("Action", String.Empty);

            return(uiButton);
        }