@@ -359,44 +359,48 @@ namespace AdaptiveCards::Rendering::Uwp::XamlHelpers
359359 return S_OK;
360360 }
361361
362- void ApplyBackgroundToRoot (_In_ IPanel* rootPanel,
363- _In_ IAdaptiveBackgroundImage* backgroundImage,
364- _In_ IAdaptiveRenderContext* renderContext,
365- _In_ IAdaptiveRenderArgs* renderArgs)
362+ void CreateBackgroundImage (_In_ IAdaptiveRenderContext* renderContext, _In_ HSTRING url, _Outptr_ IImage** backgroundImage)
366363 {
367- // In order to reuse the image creation code paths, we simply create an adaptive card
368- // image element and then build that into xaml and apply to the root.
369- ComPtr<IAdaptiveImage> adaptiveImage = XamlHelpers::CreateABIClass<IAdaptiveImage>(
370- HStringReference (RuntimeClass_AdaptiveCards_ObjectModel_Uwp_AdaptiveImage));
364+ ComPtr<IImage> image = XamlHelpers::CreateABIClass<IImage>(HStringReference (RuntimeClass_Windows_UI_Xaml_Controls_Image));
371365
372- HString url;
373- THROW_IF_FAILED (backgroundImage->get_Url (url.GetAddressOf ()));
374- THROW_IF_FAILED (adaptiveImage->put_Url (url.Get ()));
366+ ComPtr<IDependencyObject> imageAsDependencyObject;
367+ THROW_IF_FAILED (image.As (&imageAsDependencyObject));
375368
376- ComPtr<IAdaptiveCardElement> adaptiveCardElement ;
377- THROW_IF_FAILED (adaptiveImage. As (&adaptiveCardElement ));
369+ ComPtr<IAdaptiveHostConfig> hostConfig ;
370+ THROW_IF_FAILED (renderContext-> get_HostConfig (&hostConfig ));
378371
379- ComPtr<IAdaptiveElementRendererRegistration> elementRenderers ;
380- THROW_IF_FAILED (renderContext-> get_ElementRenderers (&elementRenderers ));
372+ ComPtr<IUriRuntimeClass> imageUrl ;
373+ GetUrlFromString (hostConfig. Get (), url, imageUrl. GetAddressOf ( ));
381374
382- ComPtr<IAdaptiveElementRenderer> elementRenderer;
383- THROW_IF_FAILED (elementRenderers->Get (HStringReference (L" Image" ).Get (), &elementRenderer));
375+ ComPtr<IBitmapImage> bitmapImage =
376+ XamlHelpers::CreateABIClass<IBitmapImage>(HStringReference (RuntimeClass_Windows_UI_Xaml_Media_Imaging_BitmapImage));
377+ THROW_IF_FAILED (bitmapImage->put_UriSource (imageUrl.Get ()));
384378
385- ComPtr<IUIElement> background;
386- if (elementRenderer != nullptr )
387- {
388- elementRenderer->Render (adaptiveCardElement.Get (), renderContext, renderArgs, &background);
389- if (background == nullptr )
390- {
391- return ;
392- }
393- }
379+ ComPtr<IImageSource> bitmapImageSource;
380+ THROW_IF_FAILED (bitmapImage.As (&bitmapImageSource));
381+
382+ ComPtr<IUIElement> imageAsUIElement;
383+ THROW_IF_FAILED (image.As (&imageAsUIElement));
384+ THROW_IF_FAILED (image->put_Source (bitmapImageSource.Get ()));
385+ THROW_IF_FAILED (image.CopyTo (backgroundImage));
386+ }
387+
388+ void ApplyBackgroundToRoot (_In_ IPanel* rootPanel,
389+ _In_ IAdaptiveBackgroundImage* backgroundImage,
390+ _In_ IAdaptiveRenderContext* renderContext)
391+ {
392+ HString url;
393+ THROW_IF_FAILED (backgroundImage->get_Url (url.GetAddressOf ()));
394394
395395 ComPtr<IImage> xamlImage;
396- THROW_IF_FAILED (background.As (&xamlImage));
396+ CreateBackgroundImage (renderContext, url.Get (), &xamlImage);
397+ if (!xamlImage)
398+ {
399+ return ;
400+ }
397401
398- ABI::AdaptiveCards::ObjectModel::Uwp::BackgroundImageFillMode fillMode ;
399- THROW_IF_FAILED (backgroundImage-> get_FillMode (&fillMode ));
402+ ComPtr<IUIElement> xamlImageAsUIElement ;
403+ THROW_IF_FAILED (xamlImage. As (&xamlImageAsUIElement ));
400404
401405 // Creates the background image for all fill modes
402406 ComPtr<TileControl> tileControl;
@@ -413,7 +417,7 @@ namespace AdaptiveCards::Rendering::Uwp::XamlHelpers
413417 THROW_IF_FAILED (rootPanel->QueryInterface (rootElement.GetAddressOf ()));
414418 THROW_IF_FAILED (tileControl->put_RootElement (rootElement.Get ()));
415419
416- THROW_IF_FAILED (tileControl->LoadImageBrush (background .Get ()));
420+ THROW_IF_FAILED (tileControl->LoadImageBrush (xamlImageAsUIElement .Get ()));
417421
418422 ComPtr<IFrameworkElement> backgroundAsFrameworkElement;
419423 THROW_IF_FAILED (tileControl.As (&backgroundAsFrameworkElement));
0 commit comments