2016-04-29 13 views
0

バインディングを介してすべてのチェックボックスをチェックしようとしています。 ボタンをクリックした後に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がインタフェース

答えて

1

をINotifyPropertyChangedのあなたのクラスVraagがINotifyPropertyChangedのインターフェイスを実装していません。実装する必要があります

public class Vraag 
{ 
    public List<string> antwoorden { get; set; } 
    public string vraag { get; set; } 
    public Boolean getChecked { get; set; } 
} 





public class VragenList : ObservableCollection<Vraag> 
{ 
    public VragenList(List<Vraag> vragen) :base() 
    { 
     foreach (var vraag in vragen) 
     { 
      Add(vraag); 
     } 
    } 
} 
+0

それはうまくいきました、ありがとうございます。 –

+0

問題ありません。 sidenodeと同じように:PropertyChangedEventHandlerとOnPropertyChanged-Methodを使ってINotifyPropertyChangedインターフェイスを実装する基本クラスを作成することは、常にあなたのUIに表示する任意のクラスで使用することができます。 –

1

したがって、UIは、ビューに表示され、あなたのオブジェクトに対して行われた変更を登録されていません。

のでbasciallyあなたがする必要がどのような種類のこのようINotifyPropertyChangedの-インタフェースを実装している:

public class Vraag : INotifyPropertyChanged 
{ 
    public List<string> antwoorden { get; set; } 
    public string vraag { get; set; } 

    private bool isChecked; 

    public bool getChecked 
    { 
     get { return isChecked; } 
     set 
     { 
      isChecked = value; 
      OnPropertyChanged(); 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    public void OnPropertyChanged([CallerMemberName] string propName = null) 
    { 
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); 
    } 
} 

・ホープ、この助けて!

関連する問題