From ca13855844badcb2f43dcb333911ae9d4e11caea Mon Sep 17 00:00:00 2001 From: Alberto Medina Gutierrez Date: Thu, 25 Jul 2019 15:06:53 -0700 Subject: [PATCH] Move inline action rendering to its own function --- .../XceedTextInput.cs | 85 +------------- .../AdaptiveTextInputRenderer.cs | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+), 84 deletions(-) diff --git a/source/dotnet/Library/AdaptiveCards.Rendering.Wpf.Xceed/XceedTextInput.cs b/source/dotnet/Library/AdaptiveCards.Rendering.Wpf.Xceed/XceedTextInput.cs index 57d081308e..b40305de33 100644 --- a/source/dotnet/Library/AdaptiveCards.Rendering.Wpf.Xceed/XceedTextInput.cs +++ b/source/dotnet/Library/AdaptiveCards.Rendering.Wpf.Xceed/XceedTextInput.cs @@ -39,90 +39,7 @@ public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderCon { if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(input.InlineAction.GetType())) { - // Set up a parent view that holds textbox, separator and button - var parentView = new Grid(); - - // grid config for textbox - parentView.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); - Grid.SetColumn(textBox, 0); - parentView.Children.Add(textBox); - - // grid config for spacing - int spacing = context.Config.GetSpacing(AdaptiveSpacing.Default); - var uiSep = new Grid - { - Style = context.GetStyle($"Adaptive.Input.Text.InlineAction.Separator"), - VerticalAlignment = VerticalAlignment.Stretch, - Width = spacing, - }; - parentView.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(spacing, GridUnitType.Pixel) }); - Grid.SetColumn(uiSep, 1); - - // adding button - var uiButton = new Button(); - Style style = context.GetStyle($"Adaptive.Input.Text.InlineAction.Button"); - if(style != null) - { - uiButton.Style = style; - } - - // this textblock becomes tooltip if icon url exists else becomes the tile for the button - var uiTitle = new TextBlock - { - Text = input.InlineAction.Title, - }; - - if (input.InlineAction.IconUrl != null) - { - var actionsConfig = context.Config.Actions; - - var image = new AdaptiveImage(input.InlineAction.IconUrl) - { - HorizontalAlignment = AdaptiveHorizontalAlignment.Center, - Type = "Adaptive.Input.Text.InlineAction.Image", - }; - - FrameworkElement uiIcon = null; - uiIcon = AdaptiveImageRenderer.Render(image, context); - uiButton.Content = uiIcon; - - // adjust height - textBox.Loaded += (sender, e) => - { - uiIcon.Height = textBox.ActualHeight; - }; - - uiButton.ToolTip = uiTitle; - } - else - { - uiTitle.FontSize = context.Config.GetFontSize(AdaptiveFontType.Default, AdaptiveTextSize.Default); - uiTitle.Style = context.GetStyle($"Adaptive.Input.Text.InlineAction.Title"); - uiButton.Content = uiTitle; - } - - uiButton.Click += (sender, e) => - { - context.InvokeAction(uiButton, new AdaptiveActionEventArgs(input.InlineAction)); - - // Prevent nested events from triggering - e.Handled = true; - }; - - parentView.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); - Grid.SetColumn(uiButton, 2); - parentView.Children.Add(uiButton); - uiButton.VerticalAlignment = VerticalAlignment.Bottom; - - textBox.KeyDown += (sender, e) => - { - if (e.Key == System.Windows.Input.Key.Enter) - { - context.InvokeAction(uiButton, new AdaptiveActionEventArgs(input.InlineAction)); - e.Handled = true; - } - }; - return parentView; + return AdaptiveTextInputRenderer.RenderInlineAction(input, context, textBox); } } } diff --git a/source/dotnet/Library/AdaptiveCards.Rendering.Wpf/AdaptiveTextInputRenderer.cs b/source/dotnet/Library/AdaptiveCards.Rendering.Wpf/AdaptiveTextInputRenderer.cs index 14ec587623..43f217118c 100644 --- a/source/dotnet/Library/AdaptiveCards.Rendering.Wpf/AdaptiveTextInputRenderer.cs +++ b/source/dotnet/Library/AdaptiveCards.Rendering.Wpf/AdaptiveTextInputRenderer.cs @@ -27,7 +27,113 @@ public static FrameworkElement Render(AdaptiveTextInput input, AdaptiveRenderCon textBox.Style = context.GetStyle($"Adaptive.Input.Text.{input.Style}"); textBox.SetContext(input); context.InputBindings.Add(input.Id, () => textBox.Text); + + + if (input.InlineAction != null) + { + if (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline && + input.InlineAction.GetType() == typeof(AdaptiveShowCardAction)) + { + context.Warnings.Add(new AdaptiveWarning(-1, "Inline ShowCard not supported for InlineAction")); + } + else + { + if (context.Config.SupportsInteractivity && context.ActionHandlers.IsSupported(input.InlineAction.GetType())) + { + return RenderInlineAction(input, context, textBox); + } + } + } + return textBox; } + + public static FrameworkElement RenderInlineAction(AdaptiveTextInput input, AdaptiveRenderContext context, FrameworkElement textBox) + { + // Set up a parent view that holds textbox, separator and button + var parentView = new Grid(); + + // grid config for textbox + parentView.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); + Grid.SetColumn(textBox, 0); + parentView.Children.Add(textBox); + + // grid config for spacing + int spacing = context.Config.GetSpacing(AdaptiveSpacing.Default); + var uiSep = new Grid + { + Style = context.GetStyle($"Adaptive.Input.Text.InlineAction.Separator"), + VerticalAlignment = VerticalAlignment.Stretch, + Width = spacing, + }; + parentView.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(spacing, GridUnitType.Pixel) }); + Grid.SetColumn(uiSep, 1); + + // adding button + var uiButton = new Button(); + Style style = context.GetStyle($"Adaptive.Input.Text.InlineAction.Button"); + if (style != null) + { + uiButton.Style = style; + } + + // this textblock becomes tooltip if icon url exists else becomes the tile for the button + var uiTitle = new TextBlock + { + Text = input.InlineAction.Title, + }; + + if (input.InlineAction.IconUrl != null) + { + var actionsConfig = context.Config.Actions; + + var image = new AdaptiveImage(input.InlineAction.IconUrl) + { + HorizontalAlignment = AdaptiveHorizontalAlignment.Center, + Type = "Adaptive.Input.Text.InlineAction.Image", + }; + + FrameworkElement uiIcon = null; + uiIcon = AdaptiveImageRenderer.Render(image, context); + uiButton.Content = uiIcon; + + // adjust height + textBox.Loaded += (sender, e) => + { + uiIcon.Height = textBox.ActualHeight; + }; + + uiButton.ToolTip = uiTitle; + } + else + { + uiTitle.FontSize = context.Config.GetFontSize(AdaptiveFontType.Default, AdaptiveTextSize.Default); + uiTitle.Style = context.GetStyle($"Adaptive.Input.Text.InlineAction.Title"); + uiButton.Content = uiTitle; + } + + uiButton.Click += (sender, e) => + { + context.InvokeAction(uiButton, new AdaptiveActionEventArgs(input.InlineAction)); + + // Prevent nested events from triggering + e.Handled = true; + }; + + parentView.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); + Grid.SetColumn(uiButton, 2); + parentView.Children.Add(uiButton); + uiButton.VerticalAlignment = VerticalAlignment.Bottom; + + textBox.KeyDown += (sender, e) => + { + if (e.Key == System.Windows.Input.Key.Enter) + { + context.InvokeAction(uiButton, new AdaptiveActionEventArgs(input.InlineAction)); + e.Handled = true; + } + }; + return parentView; + } } }