回答編集履歴

1

見直しキャンペーン中

2023/07/21 09:08

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,39 +1,20 @@
1
1
  WPFで試しました(`ReactiveProperty`については差はないと思います)
2
-
3
2
  こちらでは想定の動作になりましたが、あまり詳しくないので間違いがあるかもしれません。
4
3
 
5
-
6
-
7
- ```C#
4
+ ```cs
8
-
9
5
  //宣言部
10
-
11
6
  public ReactiveProperty<string> InputSerial { get; } = new ReactiveProperty<string>();
12
-
13
7
  public ReactiveCommand BtnInputSerial { get; }
14
-
15
8
  public ReactiveCollection<string> ItemSerialsUse { get; } = new ReactiveCollection<string>();
16
9
 
17
-
18
-
19
10
  //コンストラクタ
20
-
21
11
  var c = ItemSerialsUse
22
-
23
12
  .CollectionChangedAsObservable()
24
-
25
13
  .StartWith(new NotifyCollectionChangedEventArgs[] { null });
26
-
27
14
  BtnInputSerial = InputSerial
28
-
29
15
  .CombineLatest(c, (x, y) => !string.IsNullOrWhiteSpace(x) && !ItemSerialsUse.Any(z => z == x))
30
-
31
16
  .ToReactiveCommand();
32
-
33
17
  BtnInputSerial.Subscribe(_ => ItemSerialsUse.Add(InputSerial.Value));
34
-
35
18
  ```
36
19
 
37
-
38
-
39
20
  `var c`は長くなったので出しただけで、深い意味はありません。