回答編集履歴
1
コード追記
test
CHANGED
@@ -9,3 +9,137 @@
|
|
9
9
|
原因は提示されているコード以外の部分にあるように思えるのですが、如何でしょうか。
|
10
10
|
|
11
11
|
(例えば、1秒毎にインクリメントしているのがフィールド変数のcountだったりとか…)
|
12
|
+
|
13
|
+
```cs
|
14
|
+
|
15
|
+
public class CClass : INotifyPropertyChanged
|
16
|
+
|
17
|
+
{
|
18
|
+
|
19
|
+
public ICommand StartTimerCommand { get; }
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
public event PropertyChangedEventHandler PropertyChanged = delegate { };
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
int count;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public CClass()
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
StartTimerCommand = new Command(() =>
|
36
|
+
|
37
|
+
{
|
38
|
+
|
39
|
+
Device.StartTimer(
|
40
|
+
|
41
|
+
TimeSpan.FromSeconds(1),
|
42
|
+
|
43
|
+
() => { Counter++; return true; });
|
44
|
+
|
45
|
+
});
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public int Counter
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
get
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
return this.count;
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
set
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
if (this.count != value)
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
this.count = value;
|
72
|
+
|
73
|
+
OnPropertyChanged("Counter");
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
protected virtual void OnPropertyChanged(string propertyName)
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
```xaml
|
96
|
+
|
97
|
+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
98
|
+
|
99
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
100
|
+
|
101
|
+
xmlns:local="clr-namespace:App1"
|
102
|
+
|
103
|
+
x:Class="App1.MainPage">
|
104
|
+
|
105
|
+
<ContentPage.BindingContext>
|
106
|
+
|
107
|
+
<local:CClass />
|
108
|
+
|
109
|
+
</ContentPage.BindingContext>
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
<StackLayout VerticalOptions="Center">
|
114
|
+
|
115
|
+
<Label Text="{Binding Counter, Mode = TwoWay, StringFormat='{0}'}"
|
116
|
+
|
117
|
+
x:name="CountLabel"
|
118
|
+
|
119
|
+
BackgroundColor="Aqua"
|
120
|
+
|
121
|
+
HorizontalTextAlignment="Center"
|
122
|
+
|
123
|
+
VerticalTextAlignment="Center"/>
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
<Button Text="Start"
|
128
|
+
|
129
|
+
Command="{Binding StartTimerCommand}"
|
130
|
+
|
131
|
+
VerticalOptions="Center"
|
132
|
+
|
133
|
+
HorizontalOptions="Center" />
|
134
|
+
|
135
|
+
</StackLayout>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
</ContentPage>
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|