以下の環境で開発しています。
●環境
ReactiveProperty 4.2.2
Prism.Unity 6.3.0
■質問
認証チェックボックスがOFFのときはユーザーテキストボックスのチェックを行わないようにしたい。
ReactivePropertyのSetValidateNotifyError内で他のIsAuthプロパティを見ているのですが、IsAuthが更新される前に処理が走ってしまい、条件に引っかかりません。
他のプロパティを更新した後にSetValidateNotifyErrorを呼び出す方法はありますか。
c#
1 public ReactiveProperty<bool> IsAuth { get; set; } = new ReactiveProperty<bool>(false); 2 public ReactiveProperty<string> User { get; set; } 3 public ReactiveProperty<IEnumerable<string>> ErrorMessages { get; private set; } 4 5 public MainWindowViewModel() 6 { 7 this.User = new ReactiveProperty<string>("") 8 .SetValidateNotifyError(x => 9 { 10 if(this.IsAuth.Value) 11 { 12 if(x.Length <= 0) 13 { 14 return "ユーザー名を入力してください。"; 15 } 16 } 17 return null; 18 }); 19 20 this.ErrorMessages = new[] 21 { 22 this.User.ObserveErrorChanged, 23 } 24 .CombineLatest(x => 25 { 26 return x.Where(y => y != null) 27 .SelectMany(y => y.OfType<string>()); 28 }) 29 .ToReactiveProperty(); 30 }
xml
1 <CheckBox x:Name="use_auth" Content="認証" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" Margin="10" 2 IsChecked="{Binding IsAuth.Value, Mode=TwoWay}"/> 3 4 <Label Content="ユーザー:" Grid.Column="0" Grid.Row="1" Margin="20,5,5,5" /> 5 <TextBox x:Name="user" Grid.Column="1" Grid.Row="1" Margin="10" 6 Text="{Binding User.Value, Mode=TwoWay}" 7 IsEnabled="{Binding IsAuth.Value, Mode=OneWay}"/> 8 9 <ItemsControl Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding ErrorMessages.Value}" Margin="10" Focusable="False"/>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/16 07:34
2018/10/16 23:30
2018/10/16 23:38
2018/10/17 02:19