From 1abcc3511a7db24995c0948bd520e8c5f3ab7f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20R=C3=B8vik=20Larsen?= Date: Sun, 30 Oct 2022 14:25:17 +0100 Subject: [PATCH 1/2] avoid setting bindings twice --- .../Core/Platform/Windows/CollectionView/ItemContentControl.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Platform/Windows/CollectionView/ItemContentControl.cs b/src/Controls/src/Core/Platform/Windows/CollectionView/ItemContentControl.cs index 8c43146a8b6d..c6181e05d028 100644 --- a/src/Controls/src/Core/Platform/Windows/CollectionView/ItemContentControl.cs +++ b/src/Controls/src/Core/Platform/Windows/CollectionView/ItemContentControl.cs @@ -168,7 +168,6 @@ internal void Realize() // or if we need to switch DataTemplates (because this instance is being recycled) // then we'll need to create the content from the template _visualElement = formsTemplate.CreateContent(dataContext, container) as VisualElement; - _visualElement.BindingContext = dataContext; _renderer = _visualElement.ToHandler(mauiContext); // We need to set IsPlatformStateConsistent explicitly; otherwise, it won't be set until the renderer's Loaded @@ -186,11 +185,11 @@ internal void Realize() { // We are reusing this ItemContentControl and we can reuse the Element _visualElement = _renderer.VirtualView as VisualElement; - _visualElement.BindingContext = dataContext; } Content = _renderer.ToPlatform(); itemsView?.AddLogicalChild(_visualElement); + _visualElement.BindingContext = dataContext; } void SetNativeStateConsistent(VisualElement visualElement) From 3a17884b499850041788a4a3e335f6530b5e319b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20R=C3=B8vik=20Larsen?= Date: Sun, 30 Oct 2022 14:25:44 +0100 Subject: [PATCH 2/2] add sample code for testing purposes --- .../CollectionViewGallery.cs | 1 + .../CollectionViewGalleries/OnlineImages.xaml | 17 +++++++++ .../OnlineImages.xaml.cs | 36 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml create mode 100644 src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml.cs diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionViewGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionViewGallery.cs index beaa8b4b78da..a810a470223a 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionViewGallery.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionViewGallery.cs @@ -50,6 +50,7 @@ public CollectionViewGallery() GalleryBuilder.NavButton("Alternate Layout Galleries", () => new AlternateLayoutGallery(), Navigation), GalleryBuilder.NavButton("Header/Footer Galleries", () => new HeaderFooterGallery(), Navigation), GalleryBuilder.NavButton("Nested CollectionViews", () => new NestedGalleries.NestedCollectionViewGallery(), Navigation), + GalleryBuilder.NavButton("Online images", () => new OnlineImages(), Navigation), } } }; diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml new file mode 100644 index 000000000000..652d71bbc66d --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml.cs new file mode 100644 index 000000000000..653f6ef22124 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/OnlineImages.xaml.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Xaml; +using Microsoft.Maui.Dispatching; + +namespace Maui.Controls.Sample.Pages.CollectionViewGalleries +{ + public record OnlineImageInfo(string Uri); + + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class OnlineImages : ContentPage + { + public OnlineImages() + { + InitializeComponent(); + + Dispatcher.DispatchAsync(SetItemsSource); + } + + async Task SetItemsSource() + { + await Task.Delay(TimeSpan.FromSeconds(1)); + + CollectionView.ItemsSource = new ObservableCollection + { + new ("https://news.microsoft.com/wp-content/uploads/prod/2022/07/hexagon_print.gif"), + new ("https://news.microsoft.com/wp-content/uploads/prod/2022/07/collaboration-controls-in-power-platform_print.gif"), + new ("https://news.microsoft.com/wp-content/uploads/prod/2022/07/Updatesin-Teams.png"), + new ("https://news.microsoft.com/wp-content/uploads/prod/2022/07/Expanded-Reactions.png"), + new ("https://news.microsoft.com/wp-content/uploads/prod/2022/04/Companion-Devices.jpg"), + }; + } + } +} \ No newline at end of file