##分からない事
以下のようなコードを書いた場合、
ListBox内のアイテムをクリックする度にCheckBoxのON/OFFが切り替わって欲しいのですが意図した動きをしてくれません。
どこがマズいのでしょうか。
<Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <CheckBox IsChecked="{Binding IsChecked}" /> <ListBox Grid.Row="1" ItemsSource="{Binding ItemSource}"> <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewMouseLeftButtonUp"> <i:InvokeCommandAction Command="{Binding PreviewMouseLeftButtonUpCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </ListBox> </Grid>
C#
1#region フィールド 2private bool _isChecked; 3#endregion 4 5#region プロパティ 6public bool IsChecked 7{ 8 get => _isChecked; 9 set => SetProperty(ref _isChecked, value); 10} 11public ObservableCollection<string> ItemSource { get; set; } 12public DelegateCommand PreviewMouseLeftButtonUpCommand { get; } 13#endregion 14 15#region コンストラクタ 16public MainWindowViewModel() 17{ 18 ItemSource = new ObservableCollection<string> 19 { 20 "hoge1", 21 "hoge2", 22 }; 23 PreviewMouseLeftButtonUpCommand = new DelegateCommand(Hoge) 24} 25#endregion 26 27#region メソッド 28private void Hoge() 29{ 30 _isChecked = !_isChecked; 31} 32#endregion 33
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。