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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using System.Collections.ObjectModel;
using System.ComponentModel;
#if UITEST
using Xamarin.UITest.Queries;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Github, 2951, "On Android, button background is not updated when color changes ")]
public partial class Issue2951 : TestContentPage
{
public Issue2951 ()
{
#if APP
InitializeComponent ();
#endif
}
protected override void Init ()
{
BindingContext = new MyViewModel ();
}
[Preserve (AllMembers = true)]
public class MyViewModel
{
public ObservableCollection<MyItemViewModel> Items { get; private set; }
public Command<MyItemViewModel> ButtonTapped { get; private set; }
public MyViewModel ()
{
ButtonTapped = new Command<MyItemViewModel> (OnItemTapped);
Items = new ObservableCollection<MyItemViewModel> ();
Items.Add (new MyItemViewModel { Name = "A", IsStarted = false });
Items.Add (new MyItemViewModel { Name = "B", IsStarted = false });
Items.Add (new MyItemViewModel { Name = "C", IsStarted = false });
}
void OnItemTapped (MyItemViewModel model)
{
if (model.IsStarted) {
Items.Remove (model);
} else {
model.IsStarted = true;
}
}
}
[Preserve (AllMembers = true)]
public class MyItemViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
string _name;
public string Name {
get { return _name; }
set {
_name = value;
OnPropertyChanged ("Name");
}
}
bool _isStarted;
public bool IsStarted {
get { return _isStarted; }
set {
_isStarted = value;
OnPropertyChanged ("IsStarted");
}
}
void OnPropertyChanged (string propertyName)
{
if (PropertyChanged != null) {
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
}
}
}
#if UITEST
[Test]
public void Issue2951Test ()
{
var bt = RunningApp.WaitForElement (c => c.Marked ("btnChangeStatus"));
var buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus"));
Assert.That (buttons.Length, Is.EqualTo (3));
RunningApp.Tap(c => c.Marked ("btnChangeStatus").Index(1));
buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus"));
var text = buttons [1].Text ?? buttons [1].Label;
Assert.That (text, Is.EqualTo ("B"));
RunningApp.Tap(c => c.Marked ("btnChangeStatus").Index(1));
buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus"));
Assert.That (buttons.Length, Is.EqualTo (2));
//TODO: we should check the color of the button
//var buttonTextColor = GetProperty<Color> ("btnChangeStatus", Button.BackgroundColorProperty);
//Assert.AreEqual (Color.Pink, buttonTextColor);
}
#endif
}
[Preserve (AllMembers = true)]
public class ButtonExtensions
{
#pragma warning disable 618
public static readonly BindableProperty IsPrimaryProperty = BindableProperty.CreateAttached<ButtonExtensions, bool> (
#pragma warning restore 618
bindable => GetIsPrimary (bindable),
false,
BindingMode.TwoWay,
null,
null,
null,
null);
public static bool GetIsPrimary (BindableObject bo)
{
return (bool)bo.GetValue (IsPrimaryProperty);
}
public static void SetIsPrimary (BindableObject bo, bool value)
{
bo.SetValue (IsPrimaryProperty, value);
}
}
}
|