From b2a78b269bb2937115453b2baca155892e3c68a1 Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Fri, 8 Jun 2018 05:20:17 +0900 Subject: [PATCH] [Core] Fix Padding of Layout Issue (#2764) fixes #2763 --- .../Issue2763.cs | 139 ++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 3 +- Xamarin.Forms.Core/Layout.cs | 2 +- 3 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs new file mode 100644 index 000000000..35a9f9d01 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs @@ -0,0 +1,139 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using Xamarin.Forms; + +namespace Xamarin.Forms.Controls +{ + // This test covers the issue reported in https://github.com/xamarin/Xamarin.Forms/issues/2763 + + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 2763, + "[Core] StakLayout Padding update issue", NavigationBehavior.PushAsync)] + public class Issue2763 : TestContentPage + { + protected override void Init() + { + StackLayout parentLayout1 = null; + StackLayout parentLayout2 = null; + StackLayout parentLayout3 = null; + + StackLayout stackLayout = new StackLayout + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + BackgroundColor = Color.Blue, + Children = + { + new BoxView + { + Color = Color.Red, + HeightRequest = 100, + WidthRequest = 100, + } + } + }; + + ContentView contentView = new ContentView + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + BackgroundColor = Color.Blue, + Content = + new BoxView + { + Color = Color.Red, + HeightRequest = 100, + WidthRequest = 100, + } + }; + + FlexLayout flex = new FlexLayout + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + BackgroundColor = Color.Blue, + Children = + { + new BoxView + { + Color = Color.Red, + HeightRequest = 100, + WidthRequest = 100, + } + } + }; + + Slider paddingSlider = new Slider + { + HorizontalOptions = LayoutOptions.FillAndExpand, + Minimum = 0.0, + Maximum = 100.0, + }; + + stackLayout.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); + contentView.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); + flex.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); + + // Build the page. + this.Padding = new Thickness(20); + this.Content = new StackLayout + { + Spacing = 20, + Children = + { + new StackLayout + { + Orientation = StackOrientation.Horizontal, + Children = + { + new Label + { + Text = "Padding" + }, + paddingSlider, + } + }, + new Button() + { + Text = "Force update", + Command = new Command(() => + { + var boxview = new BoxView(); + parentLayout1.Children.Add(boxview); + parentLayout1.Children.Remove(boxview); + parentLayout2.Children.Add(boxview); + parentLayout2.Children.Remove(boxview); + parentLayout3.Children.Add(boxview); + parentLayout3.Children.Remove(boxview); + }) + }, + new ScrollView + { + HorizontalOptions = LayoutOptions.FillAndExpand, + VerticalOptions = LayoutOptions.FillAndExpand, + Content = new StackLayout + { + Spacing = 20, + Children = + { + (parentLayout1 = new StackLayout + { + Children = { new Label { Text = "StackLayout" }, stackLayout }, + }), + (parentLayout2 = new StackLayout + { + Children = { new Label { Text = "ContentView" }, contentView } + }), + (parentLayout3 = new StackLayout + { + Children = { new Label { Text = "FlexLayout" }, flex } + }) + + } + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index b51a96ea0..e94078fde 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -253,6 +253,7 @@ + @@ -910,4 +911,4 @@ MSBuild:UpdateDesignTimeXaml - \ No newline at end of file + diff --git a/Xamarin.Forms.Core/Layout.cs b/Xamarin.Forms.Core/Layout.cs index da640aeba..69a9ec208 100644 --- a/Xamarin.Forms.Core/Layout.cs +++ b/Xamarin.Forms.Core/Layout.cs @@ -102,7 +102,7 @@ namespace Xamarin.Forms void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) { - UpdateChildrenLayout(); + InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged); } internal ObservableCollection InternalChildren { get; } = new ObservableCollection();