|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using Xamarin.Forms.Internals; |
| 5 | +using Xamarin.Forms.CustomAttributes; |
| 6 | +using System.ComponentModel; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace Xamarin.Forms.Controls.Issues |
| 10 | +{ |
| 11 | + [Issue(IssueTracker.Github, 9451, |
| 12 | + "[Bug] RelativeLayout Constraint can not go back to zero", PlatformAffected.All)] |
| 13 | + public class Issue9451 : TestContentPage |
| 14 | + { |
| 15 | + public StackLayout StackLayout { get; set; } |
| 16 | + public Button TriggerButton { get; set; } |
| 17 | + |
| 18 | + protected override void Init() |
| 19 | + { |
| 20 | + var relativeLayout = new RelativeLayout() { WidthRequest = 400, HeightRequest = 400 }; |
| 21 | + StackLayout = new StackLayout() { BackgroundColor = Color.Red }; |
| 22 | + |
| 23 | + TriggerButton = new Button() { Text = "Set View Width To Zero" }; |
| 24 | + |
| 25 | + StackLayout.Children.Add(TriggerButton); |
| 26 | + |
| 27 | + relativeLayout.Children.Add(StackLayout, |
| 28 | + Xamarin.Forms.Constraint.Constant(0), |
| 29 | + Xamarin.Forms.Constraint.Constant(0), |
| 30 | + Xamarin.Forms.Constraint.RelativeToParent(x => x.Width / 2), |
| 31 | + Xamarin.Forms.Constraint.RelativeToParent(y => y.Height)); |
| 32 | + |
| 33 | + Content = relativeLayout; |
| 34 | + } |
| 35 | + |
| 36 | + protected override void OnAppearing() |
| 37 | + { |
| 38 | + base.OnAppearing(); |
| 39 | + |
| 40 | + TriggerButton.Clicked += Button_Clicked; |
| 41 | + } |
| 42 | + |
| 43 | + protected override void OnDisappearing() |
| 44 | + { |
| 45 | + base.OnDisappearing(); |
| 46 | + |
| 47 | + TriggerButton.Clicked -= Button_Clicked; |
| 48 | + } |
| 49 | + |
| 50 | + private void Button_Clicked(object sender, EventArgs e) |
| 51 | + { |
| 52 | + RelativeLayout.SetWidthConstraint(StackLayout, Xamarin.Forms.Constraint.Constant(0.0)); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments