From e7951bb4b10e164743f4e301d08f271d1048bbcd Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Wed, 12 Jun 2019 15:33:21 -0400 Subject: [PATCH] Fix iOS items dependency property propagation --- .../UITests.Shared/UITests.Shared.projitems | 8 ++++ .../ListView_DataContext_Propagation.xaml | 48 +++++++++++++++++++ .../ListView_DataContext_Propagation.xaml.cs | 34 +++++++++++++ .../ListViewBase/ListViewBaseSource.iOS.cs | 6 ++- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml.cs diff --git a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems index 73061e3dfb9c..fdd1ee8b4316 100644 --- a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems +++ b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems @@ -689,6 +689,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -2229,6 +2233,7 @@ ListViewResizableText.xaml + ListView_Infinite_Breadth.xaml @@ -3132,6 +3137,9 @@ Simpletwocolumnsplitgrid.xaml + + ListView_DataContext_Propagation.xaml + diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml new file mode 100644 index 000000000000..6870dba63136 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + Item 01 + Item 02 + + + + diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml.cs new file mode 100644 index 000000000000..cb331d9872ed --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ListView/ListView_DataContext_Propagation.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Uno.UI.Samples.Controls; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + +namespace UITests.Shared.Windows_UI_Xaml_Controls.ListView +{ + [SampleControlInfo("ListView", "ListView_DataContext_Propagation")] + public sealed partial class ListView_DataContext_Propagation : UserControl + { + public ListView_DataContext_Propagation() + { + this.InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + topGrid.DataContext = "Button Clicked " + sender.ToString(); + } + } +} diff --git a/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBaseSource.iOS.cs b/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBaseSource.iOS.cs index 4b15333518ff..b8aa158c8651 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBaseSource.iOS.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBaseSource.iOS.cs @@ -229,7 +229,11 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS } FrameworkElement.InitializePhaseBinding(selectorItem); - } + + // Ensure the item has a parent, since it's added to the native collection view + // which does not automatically sets the parent DependencyObject. + selectorItem.SetParent(Owner?.XamlParent); + } else if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Debug($"Reusing view at indexPath={indexPath}, previously bound to {selectorItem.DataContext}.");