回答編集履歴
2
コード修正
answer
CHANGED
@@ -29,11 +29,11 @@
|
|
29
29
|
```C#
|
30
30
|
public ViewModel ()
|
31
31
|
{
|
32
|
-
XValues = ModelInstance.Positions.Select(positions => positions.Select(position => (int)position.X).ToList()).
|
32
|
+
XValues = ModelInstance.Positions.Select(positions => positions.Select(position => (int)position.X).ToList()).ToReactiveProperty().AddTo(_disposable);
|
33
|
-
YValues = ModelInstance.Positions.Select(positions => positions.Select(position => (int)position.Y).ToList()).
|
33
|
+
YValues = ModelInstance.Positions.Select(positions => positions.Select(position => (int)position.Y).ToList()).ToReactiveProperty().AddTo(_disposable);
|
34
34
|
}
|
35
35
|
|
36
|
-
public
|
36
|
+
public ReactiveProperty<List<int>> XValues { get; }
|
37
37
|
|
38
|
-
public
|
38
|
+
public ReactiveProperty<List<int>> YValues { get; }
|
39
39
|
```
|
1
別の方法を追記
answer
CHANGED
@@ -21,4 +21,19 @@
|
|
21
21
|
public ReadOnlyReactiveCollection<int> XValues { get; }
|
22
22
|
|
23
23
|
public ReadOnlyReactiveCollection<int> YValues { get; }
|
24
|
+
```
|
25
|
+
|
26
|
+
---
|
27
|
+
上記の方法では、`Positions`の操作(追加、移動など)に応じて,`XValues`や`YValues`も変わるようになりますが,`Positions`のリストを丸ごと変えるだけというのであれば、`Model`はそのままで、`ViewModel`を以下のように修正するのでもいいかもしれません。
|
28
|
+
|
29
|
+
```C#
|
30
|
+
public ViewModel ()
|
31
|
+
{
|
32
|
+
XValues = ModelInstance.Positions.Select(positions => positions.Select(position => (int)position.X).ToList()).ToReadOnlyReactiveProperty().AddTo(_disposable);
|
33
|
+
YValues = ModelInstance.Positions.Select(positions => positions.Select(position => (int)position.Y).ToList()).ToReadOnlyReactiveProperty().AddTo(_disposable);
|
34
|
+
}
|
35
|
+
|
36
|
+
public ReadOnlyReactiveProperty<List<int>> XValues { get; }
|
37
|
+
|
38
|
+
public ReadOnlyReactiveProperty<List<int>> YValues { get; }
|
24
39
|
```
|