Skip to content

Commit

Permalink
[UWP Renderer] Do not wrap textblock in ComboBoxItem for compact choi…
Browse files Browse the repository at this point in the history
…ceset (#8221)

* Do not wrap textblock in ComboBoxItem for compact choiceset

* Simplify logic
  • Loading branch information
anna-dingler authored Jan 10, 2023
1 parent e87a4d4 commit a304b52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
6 changes: 1 addition & 5 deletions source/uwp/Renderer/lib/AdaptiveChoiceSetInputRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,12 @@ namespace winrt::AdaptiveCards::Rendering::Uwp::implementation
{
auto title = adaptiveChoiceInput.Title();

winrt::ComboBoxItem comboBoxItem{};

XamlHelpers::SetContent(comboBoxItem, title, wrap);

if (values.size() == 1 && IsChoiceSelected(values, adaptiveChoiceInput))
{
// If multiple values are specified, no option is selected
selectedIndex = currentIndex;
}
items.Append(comboBoxItem);
items.Append(XamlHelpers::CreateTextBlockWithContent(title, wrap));
currentIndex++;
}

Expand Down
12 changes: 12 additions & 0 deletions source/uwp/Renderer/lib/XamlHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ namespace AdaptiveCards::Rendering::Uwp::XamlHelpers
columnDefinition.Width(CalculateColumnWidth(true, false, false, isWidthUnset, pixelWidth, width));
}

winrt::TextBlock CreateTextBlockWithContent(winrt::hstring const& contentString, bool wrap)
{
winrt::TextBlock content{};
content.Text(contentString);
if (wrap)
{
content.TextWrapping(winrt::TextWrapping::WrapWholeWords);
}

return content;
}

winrt::Image CreateBackgroundImage(winrt::AdaptiveRenderContext const& renderContext, winrt::hstring const& url)
{
try
Expand Down
11 changes: 3 additions & 8 deletions source/uwp/Renderer/lib/XamlHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace AdaptiveCards::Rendering::Uwp::XamlHelpers
return GetValueFromRef(toggleButton.IsChecked(), false);
}

winrt::TextBlock CreateTextBlockWithContent(winrt::hstring const& contentString, bool wrap);

template<typename T> void SetContent(T const& item, winrt::hstring const& contentString)
{
SetContent(item, contentString, false /* wrap */);
Expand All @@ -70,14 +72,7 @@ namespace AdaptiveCards::Rendering::Uwp::XamlHelpers
{
if (const auto contentControl = item.try_as<winrt::ContentControl>())
{
winrt::TextBlock content{};
content.Text(contentString);

if (wrap)
{
content.TextWrapping(winrt::TextWrapping::WrapWholeWords);
}
contentControl.Content(content);
contentControl.Content(CreateTextBlockWithContent(contentString, wrap));
}
}

Expand Down

0 comments on commit a304b52

Please sign in to comment.