diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2394.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2394.cs new file mode 100644 index 000000000..8e91da809 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2394.cs @@ -0,0 +1,49 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 2394, "[WPF] StackLayout VerticalOptions = LayoutOptions.End is not working", PlatformAffected.WPF)] + public class Issue2394 : TestContentPage + { + protected override void Init() + { + if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet) + Padding = new Thickness(0, 0, 0, 60); + + var stack = new StackLayout { VerticalOptions = LayoutOptions.End }; + Button b1 = new Button { Text = "Boring", HeightRequest = 100, MinimumHeightRequest = 50 }; + Button b2 = new Button + { + Text = "Exciting!", + VerticalOptions = LayoutOptions.FillAndExpand, + HorizontalOptions = LayoutOptions.CenterAndExpand + }; + Button b3 = new Button { Text = "Amazing!", VerticalOptions = LayoutOptions.FillAndExpand }; + Button b4 = new Button { Text = "Meh", HeightRequest = 100, MinimumHeightRequest = 50 }; + b1.Clicked += (sender, e) => { + b1.Text = "clicked1"; + }; + b2.Clicked += (sender, e) => { + b2.Text = "clicked2"; + }; + b3.Clicked += (sender, e) => { + b3.Text = "clicked3"; + }; + b4.Clicked += (sender, e) => { + b4.Text = "clicked4"; + }; + stack.Children.Add(b1); + stack.Children.Add(b2); + stack.Children.Add(b3); + stack.Children.Add(b4); + Content = stack; + } + } +} 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 1ed4acd78..f32dc439c 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 @@ -294,6 +294,7 @@ + diff --git a/Xamarin.Forms.Platform.WPF/Renderers/ViewRenderer.cs b/Xamarin.Forms.Platform.WPF/Renderers/ViewRenderer.cs index 8410431bf..05f3ae6f8 100644 --- a/Xamarin.Forms.Platform.WPF/Renderers/ViewRenderer.cs +++ b/Xamarin.Forms.Platform.WPF/Renderers/ViewRenderer.cs @@ -1,14 +1,8 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Threading; using WControl = System.Windows.Controls.Control; namespace Xamarin.Forms.Platform.WPF @@ -125,8 +119,7 @@ namespace Xamarin.Forms.Platform.WPF var args = new VisualElementChangedEventArgs(e.OldElement, e.NewElement); for (var i = 0; i < _elementChangedHandlers.Count; i++) _elementChangedHandlers[i](this, args); - - UpdateRequests(); + ElementChanged?.Invoke(this, e); } @@ -134,10 +127,10 @@ namespace Xamarin.Forms.Platform.WPF { if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName) UpdateEnabled(); - else if (e.PropertyName == Frame.HeightRequestProperty.PropertyName) - UpdateRequests(); - else if (e.PropertyName == Frame.WidthRequestProperty.PropertyName) - UpdateRequests(); + else if (e.PropertyName == Frame.HeightProperty.PropertyName) + UpdateHeight(); + else if (e.PropertyName == Frame.WidthProperty.PropertyName) + UpdateWidth(); else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) UpdateBackground(); else if (e.PropertyName == View.HorizontalOptionsProperty.PropertyName || e.PropertyName == View.VerticalOptionsProperty.PropertyName) @@ -201,15 +194,22 @@ namespace Xamarin.Forms.Platform.WPF control.UpdateDependencyColor(WControl.BackgroundProperty, Element.BackgroundColor); } - protected virtual void UpdateRequests() + protected virtual void UpdateHeight() + { + if (Control == null || Element == null) + return; + + Control.Height = Element.Height > 0 ? Element.Height : Double.NaN; + } + + protected virtual void UpdateWidth() { if (Control == null || Element == null) return; - Control.Width = Element.WidthRequest >= 0 ? Element.WidthRequest : Double.NaN; - Control.Height = Element.HeightRequest >= 0 ? Element.HeightRequest : Double.NaN; + Control.Width = Element.Width > 0 ? Element.Width : Double.NaN; } - + protected virtual void UpdateNativeWidget() { UpdateEnabled();