1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls
{
[Preserve (AllMembers=true)]
[Issue (IssueTracker.Github, 1758, "LayoutTo needs to be smarted about using layout specific API calls", PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.WinPhone)]
public class Issue1758 : ContentPage
{
ListView _list;
Button _button;
public Issue1758()
{
_list = new ListView { ItemsSource = new[] { "hello", "world", "from", "xamarin", "forms" } };
_button = new Button { Text = "Button" };
// The same behavior happens for both Absolute and Relative layout.
//var layout = true ? Relative() : Absolute();
var layout = Relative();
Animate();
Content = layout;
}
Layout Relative()
{
var layout = new RelativeLayout();
layout.Children.Add(_list,
Forms.Constraint.RelativeToParent(p => p.X),
Forms.Constraint.RelativeToParent(p => p.Y),
Forms.Constraint.RelativeToParent(p => p.Width),
Forms.Constraint.RelativeToParent(p => p.Height)
);
layout.Children.Add(_button,
Forms.Constraint.Constant(0),
Forms.Constraint.Constant(300));
return layout;
}
Layout Absolute()
{
var layout = new AbsoluteLayout { Children = { _list, _button } };
AbsoluteLayout.SetLayoutBounds(_list, new Rectangle(0, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutBounds(_button, new Rectangle(0, 300, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
return layout;
}
async void Animate()
{
// Comment this delay out to see the bug
// await Task.Delay(500);
await _button.LayoutTo(new Rectangle(100, 100, 100, 100), 1000);
}
}
}
|