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

回答編集履歴

1

見直しキャンペーン中

2023/07/21 09:08

投稿

TN8001
TN8001

スコア10104

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