アイテムソースにSelectedFlagブールプロパティを持つList(of T)が含まれているリストボックスがあります。ビューモデルはユーザーコントロールのDataContextとして設定されており、チェックボックスを変更してもプロパティの変更を取得できないことを除いて、すべてが期待どおりに機能しています。
これが私のxamlリストボックスです
<ListBox x:Name="lstRole" ItemsSource="{Binding Path=FAccountFunctions, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="Id">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Path=SelectedFlag, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" />
<TextBlock Text="{Binding Path=FunctionDesc}" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
チェックボックスがオンになったらFilter()関数を呼び出す必要があり、通常はUpdateSourcTrigger=PropertyChangedを設定してこれを機能させます。
Public Property FAccountFunctions As List(Of FunctionType)
Get
Return _faccountFunctions
End Get
Set(ByVal value As List(Of FunctionType))
_faccountFunctions = value
Filter()
End Set
End Property
PropertyChangedEventは、FAccountFunctionsコレクションの'SelectedFlag'プロパティで発生します。プロパティSelectedFlagの1つが変更されたときに、アイテムソースでイベントを発生させるにはどうすればよいですか?
FAccountFunctionsプロパティをObservableCollectionに変更しました...運がありません。