質問するログイン新規登録

質問編集履歴

1

コード追加

2017/06/09 08:07

投稿

otaota
otaota

スコア30

title CHANGED
File without changes
body CHANGED
@@ -130,4 +130,95 @@
130
130
  ###補足情報(言語/FW/ツール等のバージョンなど)
131
131
  Xamarin 6.3(build 864)
132
132
  Mac Note Pro
133
- OS X Yosemite(10.10.5)
133
+ OS X Yosemite(10.10.5)
134
+
135
+ ###追記コード
136
+ ```
137
+ using System;
138
+ using System.Diagnostics;
139
+ using System.Collections.Generic;
140
+ using System.Collections.ObjectModel;
141
+ using System.Linq;
142
+
143
+ using Xamarin.Forms;
144
+
145
+ namespace XaCurry
146
+ {
147
+ public class Test2Page : ContentPage
148
+ {
149
+ public Test2Page()
150
+ {
151
+ var ar = new List<MyCell>();
152
+ for (var i = 0; i < 5; i++)
153
+ {
154
+ ar.Add(new MyCell
155
+ {
156
+ No = i,
157
+ Text = "Item" + i,
158
+ });
159
+ }
160
+
161
+ MakePage(ar);
162
+ }
163
+
164
+ public void MakePage( List<MyCell> ar )
165
+ {
166
+ var listItems = new ListView
167
+ {
168
+ ItemsSource = ar,
169
+ };
170
+ listItems.ItemTemplate = new DataTemplate(() =>
171
+ {
172
+ var no = new Label();
173
+ no.SetBinding(Label.TextProperty, "No");
174
+ var text = new Label();
175
+ text.SetBinding(Label.TextProperty, "Text");
176
+
177
+ return new ViewCell
178
+ {
179
+ View = new StackLayout
180
+ {
181
+ Padding = new Thickness(20, 10, 20, 10),
182
+ Spacing = 10,
183
+ Orientation = StackOrientation.Horizontal,
184
+
185
+ Children =
186
+ {
187
+ no,
188
+ text,
189
+ },
190
+ },
191
+ };
192
+ });
193
+
194
+ listItems.ItemSelected += async(sender, e) =>
195
+ {
196
+ bool flag = await DisplayAlert("Alert Title", e.SelectedItem + " is selected.", "OK", "Cancel");
197
+ if (flag)
198
+ {
199
+ // ここで選択したセル内のラベルを書き換えたい
200
+ var i = ar.IndexOf(((MyCell)e.SelectedItem));
201
+ ar[i].Text = "@" + ar[i].Text;
202
+
203
+ MakePage(ar);
204
+ }
205
+ };
206
+
207
+ Content = new StackLayout
208
+ {
209
+ Children = {
210
+ listItems,
211
+ }
212
+ };
213
+ }
214
+ }
215
+
216
+ public class MyCell
217
+ {
218
+ public int No { get; set; }
219
+ public string Text { get; set; }
220
+ }
221
+ }
222
+
223
+
224
+ ```