質問編集履歴

1

コード追加

2017/06/09 08:07

投稿

otaota
otaota

スコア30

test CHANGED
File without changes
test CHANGED
@@ -263,3 +263,185 @@
263
263
  Mac Note Pro
264
264
 
265
265
  OS X Yosemite(10.10.5)
266
+
267
+
268
+
269
+ ###追記コード
270
+
271
+ ```
272
+
273
+ using System;
274
+
275
+ using System.Diagnostics;
276
+
277
+ using System.Collections.Generic;
278
+
279
+ using System.Collections.ObjectModel;
280
+
281
+ using System.Linq;
282
+
283
+
284
+
285
+ using Xamarin.Forms;
286
+
287
+
288
+
289
+ namespace XaCurry
290
+
291
+ {
292
+
293
+ public class Test2Page : ContentPage
294
+
295
+ {
296
+
297
+ public Test2Page()
298
+
299
+ {
300
+
301
+ var ar = new List<MyCell>();
302
+
303
+ for (var i = 0; i < 5; i++)
304
+
305
+ {
306
+
307
+ ar.Add(new MyCell
308
+
309
+ {
310
+
311
+ No = i,
312
+
313
+ Text = "Item" + i,
314
+
315
+ });
316
+
317
+ }
318
+
319
+
320
+
321
+ MakePage(ar);
322
+
323
+ }
324
+
325
+
326
+
327
+ public void MakePage( List<MyCell> ar )
328
+
329
+ {
330
+
331
+ var listItems = new ListView
332
+
333
+ {
334
+
335
+ ItemsSource = ar,
336
+
337
+ };
338
+
339
+ listItems.ItemTemplate = new DataTemplate(() =>
340
+
341
+ {
342
+
343
+ var no = new Label();
344
+
345
+ no.SetBinding(Label.TextProperty, "No");
346
+
347
+ var text = new Label();
348
+
349
+ text.SetBinding(Label.TextProperty, "Text");
350
+
351
+
352
+
353
+ return new ViewCell
354
+
355
+ {
356
+
357
+ View = new StackLayout
358
+
359
+ {
360
+
361
+ Padding = new Thickness(20, 10, 20, 10),
362
+
363
+ Spacing = 10,
364
+
365
+ Orientation = StackOrientation.Horizontal,
366
+
367
+
368
+
369
+ Children =
370
+
371
+ {
372
+
373
+ no,
374
+
375
+ text,
376
+
377
+ },
378
+
379
+ },
380
+
381
+ };
382
+
383
+ });
384
+
385
+
386
+
387
+ listItems.ItemSelected += async(sender, e) =>
388
+
389
+ {
390
+
391
+ bool flag = await DisplayAlert("Alert Title", e.SelectedItem + " is selected.", "OK", "Cancel");
392
+
393
+ if (flag)
394
+
395
+ {
396
+
397
+ // ここで選択したセル内のラベルを書き換えたい
398
+
399
+ var i = ar.IndexOf(((MyCell)e.SelectedItem));
400
+
401
+ ar[i].Text = "@" + ar[i].Text;
402
+
403
+
404
+
405
+ MakePage(ar);
406
+
407
+ }
408
+
409
+ };
410
+
411
+
412
+
413
+ Content = new StackLayout
414
+
415
+ {
416
+
417
+ Children = {
418
+
419
+ listItems,
420
+
421
+ }
422
+
423
+ };
424
+
425
+ }
426
+
427
+ }
428
+
429
+
430
+
431
+ public class MyCell
432
+
433
+ {
434
+
435
+ public int No { get; set; }
436
+
437
+ public string Text { get; set; }
438
+
439
+ }
440
+
441
+ }
442
+
443
+
444
+
445
+
446
+
447
+ ```