From fa853ff823272af4b307521d4b5774165d1c7e2c Mon Sep 17 00:00:00 2001 From: Peter Moore <13384523+legistek@users.noreply.github.com> Date: Tue, 9 Jul 2019 05:10:13 -0500 Subject: [PATCH] RelativeSource Binding (#4375) RelativeSource Binding - fixes #3847 Implement RelativeSource binding modes for Self, TemplatedParent, and FindAncestor. Add unit tests. Pare down TemplateBinding class to use RelativeSource binding mechanism. * Include RelativeSource member in Binding.Clone * Fix issue of unit tests being tricked by async in Binding.Apply; permit "Source={RelativeSource...}" in addition to "RelativeSource={RelativeSource..."; allow FindAncestor relative binding source mode to be based on BindingContext type or control type * Fix unit test wasn't actually testing "Source={RelativeSource...}" syntax. * Address @StephaneDelcroix's comments. Make FindAncestor relative source binding work even when the ancestor changes. * Much better mechanism for detecting when a parent changes for relativesource * Cleanup * more cleanup * more cleanup * Remove async/await for identifying templated parent and ancestor type binding source * Remove unused code; fix linting * Update Xamarin.Forms.Core/Binding.cs Co-Authored-By: Stephane Delcroix * Update Xamarin.Forms.Core/Binding.cs Co-Authored-By: Stephane Delcroix * Update Xamarin.Forms.Core/Binding.cs Co-Authored-By: Stephane Delcroix * Update Xamarin.Forms.Core/BindingExpression.cs Co-Authored-By: Stephane Delcroix * Update Xamarin.Forms.Core/BindingExpression.cs Co-Authored-By: Stephane Delcroix * Update Xamarin.Forms.Core/Binding.cs Co-Authored-By: Stephane Delcroix * Ensure TemplateBinding works correctly when reparenting. Cleanup. * Finish addressing comments; linting cleanup * Remove private modifier where unneeded --- .../Github3847.xaml | 35 ++++ .../Github3847.xaml.cs | 78 ++++++++ .../PerformanceTrackerTemplate.cs | 8 +- .../Xamarin.Forms.Controls.Issues.Shared.projitems | 10 + .../ControlTemplateTests.cs | 4 +- .../RelativeSourceBindingTests.cs | 211 +++++++++++++++++++++ .../Xamarin.Forms.Core.UnitTests.csproj | 1 + Xamarin.Forms.Core/Binding.cs | 125 +++++++++++- Xamarin.Forms.Core/BindingExpression.cs | 110 +++++++++++ Xamarin.Forms.Core/ContentPresenter.cs | 2 +- Xamarin.Forms.Core/Element.cs | 34 ++++ Xamarin.Forms.Core/ElementTemplate.cs | 3 + Xamarin.Forms.Core/RelativeBindingSource.cs | 61 ++++++ Xamarin.Forms.Core/RelativeBindingSourceMode.cs | 12 ++ Xamarin.Forms.Core/TemplateBinding.cs | 3 +- Xamarin.Forms.Pages/ListDataPage.cs | 6 +- Xamarin.Forms.Xaml.UnitTests/Issues/Gh3847.xaml | 47 +++++ Xamarin.Forms.Xaml.UnitTests/Issues/Gh3847.xaml.cs | 77 ++++++++ .../MarkupExtensions/RelativeSourceExtension.cs | 83 ++++++++ .../MarkupExtensions/TemplateBindingExtension.cs | 10 +- 20 files changed, 903 insertions(+), 17 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3847.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3847.xaml.cs create mode 100644 Xamarin.Forms.Core.UnitTests/RelativeSourceBindingTests.cs create mode 100644 Xamarin.Forms.Core/RelativeBindingSource.cs create mode 100644 Xamarin.Forms.Core/RelativeBindingSourceMode.cs create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Gh3847.xaml create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Gh3847.xaml.cs create mode 100644 Xamarin.Forms.Xaml/MarkupExtensions/RelativeSourceExtension.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3847.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3847.xaml new file mode 100644 index 0000000..30be783 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3847.xaml @@ -0,0 +1,35 @@ + + + + + +