Skip to content

Commit

Permalink
[.NET][WPF] Fix Action Fallback rendering for unknown elements (micro…
Browse files Browse the repository at this point in the history
…soft#2837)

* Fix Action Fallback rendering

* Remove comment

* Fix comment
  • Loading branch information
almedina-ms committed May 21, 2019
1 parent db0c951 commit 738bcdf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public static void AddActions(Grid uiContainer, IList<AdaptiveAction> actions, A
// add actions
var uiAction = (Button)context.Render(action);

if (uiAction == null)
{
continue;
}

if (actionsConfig.ActionsOrientation == ActionsOrientation.Horizontal)
{
Expand Down Expand Up @@ -146,9 +150,8 @@ private static List<AdaptiveAction> GetActionsToProcess(IList<AdaptiveAction> ac
context.Warnings.Add(new AdaptiveWarning((int)AdaptiveWarning.WarningStatusCode.MaxActionsExceeded, "Some actions were not rendered due to exceeding the maximum number of actions allowed"));
}

// only consider known actions for ActionsToProcess
var actionsToProcess = actions.Where(obj => obj.GetType() != typeof(AdaptiveUnknownAction)).ToList();
return actionsToProcess.Take(maxActions).ToList();
// just take the first maxActions actions
return actions.Take(maxActions).ToList();
}
}
}
9 changes: 4 additions & 5 deletions source/dotnet/Library/AdaptiveCards/AdaptiveActionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ public class AdaptiveActionSet : AdaptiveElement
/// </summary>
[JsonConverter(typeof(IgnoreEmptyItemsConverter<AdaptiveAction>))]
#if !NETSTANDARD1_3
[XmlArray("Actions")]
[XmlArrayItem(ElementName = "OpenUrl", Type = typeof(AdaptiveOpenUrlAction))]
[XmlArrayItem(ElementName = "ShowCard", Type = typeof(AdaptiveShowCardAction))]
[XmlArrayItem(ElementName = "Submit", Type = typeof(AdaptiveSubmitAction))]
[XmlArrayItem(ElementName = "ToggleVisibility", Type = typeof(AdaptiveToggleVisibilityAction))]
[XmlElement(typeof(AdaptiveOpenUrlAction))]
[XmlElement(typeof(AdaptiveShowCardAction))]
[XmlElement(typeof(AdaptiveSubmitAction))]
[XmlElement(typeof(AdaptiveToggleVisibilityAction))]
#endif
public List<AdaptiveAction> Actions { get; set; } = new List<AdaptiveAction>();
}
Expand Down
9 changes: 4 additions & 5 deletions source/dotnet/Library/AdaptiveCards/AdaptiveCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ public AdaptiveCard(AdaptiveSchemaVersion schemaVersion)
[JsonProperty(Order = -2)]
[JsonConverter(typeof(IgnoreEmptyItemsConverter<AdaptiveAction>))]
#if !NETSTANDARD1_3
[XmlArray("Actions")]
[XmlArrayItem(ElementName = "OpenUrl", Type = typeof(AdaptiveOpenUrlAction))]
[XmlArrayItem(ElementName = "ShowCard", Type = typeof(AdaptiveShowCardAction))]
[XmlArrayItem(ElementName = "Submit", Type = typeof(AdaptiveSubmitAction))]
[XmlArrayItem(ElementName = "ToggleVisibility", Type = typeof(AdaptiveToggleVisibilityAction))]
[XmlElement(typeof(AdaptiveOpenUrlAction))]
[XmlElement(typeof(AdaptiveShowCardAction))]
[XmlElement(typeof(AdaptiveSubmitAction))]
[XmlElement(typeof(AdaptiveToggleVisibilityAction))]
#endif
public List<AdaptiveAction> Actions { get; set; } = new List<AdaptiveAction>();

Expand Down
5 changes: 4 additions & 1 deletion source/dotnet/Samples/WPFVisualizer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@
<xctk:PropertyGrid Grid.Row="1" Grid.Column="4" Name="hostConfigEditor" PropertyValueChanged="HostConfigEditor_OnPropertyValueChanged" Visibility="Visible" >
</xctk:PropertyGrid>

<StackPanel Grid.Row="2" Grid.Column="0" Name="cardError" />
<ScrollViewer Grid.Row="2" Grid.Column="0" MaxHeight="200">
<StackPanel Name="cardError" />
</ScrollViewer>


<StackPanel Grid.Row="2" Grid.Column="4" Name="hostConfigerror" />

Expand Down

0 comments on commit 738bcdf

Please sign in to comment.