バインディングを介してすべてのチェックボックスをチェックしようとしています。 ボタンをクリックした後にgetCheckedプロパティがtrueに変更されますが、チェックボックスはチェックされません。誰かが私がここで間違っていることを見ていますか?これはリストボックスのXAMLコードです。リストボックスのチェックボックスがバインドでチェックされていない
<ListBox Name="scroll" ItemContainerStyle ="{StaticResource _ListBoxItemStyle}" Tag="{Binding SortingIndex}" BorderBrush="#C62828" BorderThickness="1" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="checkboxStack">
<CheckBox IsChecked="{Binding Path=getChecked}" Content="{Binding Path=vraag}" Style="{StaticResource LifesaversCheckBoxesA}"/>
<StackPanel Margin="20,0,0,0">
<RadioButton GroupName="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=Tag}" Content="{Binding Path=antwoorden[0]}" FontSize="15" />
<RadioButton GroupName="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=Tag}" Content="{Binding Path=antwoorden[1]}" FontSize="15" />
<RadioButton GroupName="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=Tag}" Content="{Binding Path=antwoorden[2]}" FontSize="15" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
これは私がvragenLijstの各vraag trueにgetCheckedのブール値を変更するために作られたボタンのイベントハンドラです。サンプルデータは、ランダムな文字列を生成するためのものです。
public partial class LivesaversWindow : UserControl
{
ObservableCollection<Vraag> vragenLijst;
public LivesaversWindow()
{
InitializeComponent();
vragenLijst = new VragenList(SampleData.vragen());
scroll.ItemsSource = vragenLijst;
}
private void alles_Selecteren(object sender, RoutedEventArgs e)
{
if ((string)select.Content == "Alles selecteren")
{
foreach(Vraag vraag in vragenLijst)
{
vraag.getChecked = true;
}
select.Content = "Alles deselecteren";
}
else
{
foreach (Vraag vraag in vragenLijst)
{
vraag.getChecked = false;
}
select.Content = "Alles selecteren";
}
}
これは私が使用している2つのクラスです。あなたのクラスVraagががインタフェース
それはうまくいきました、ありがとうございます。 –
問題ありません。 sidenodeと同じように:PropertyChangedEventHandlerとOnPropertyChanged-Methodを使ってINotifyPropertyChangedインターフェイスを実装する基本クラスを作成することは、常にあなたのUIに表示する任意のクラスで使用することができます。 –