我有一個ListBox中的複選框。我將ListBox ItemsSource設置爲代理列表。代理有一個屬性幫助DataBinding複選框WPF
public class Agency
{
public bool isSelected { get; set;}
}
<ListBox> <!-- ItemsSource set in codebehind to List<Agency> -->
<CheckBox IsChecked="{Binding Path=isSelected, Mode=TwoWay}" />
</ListBox>
我有一個函數來檢查所有的複選框
//SelectAll button
private void SelectAll_Click(object sender, RoutedEventArgs e)
{
List<Agency> list = this.AgencySubListBox.ItemsSource as List<Agency>;
for (int i = 0; i < list.Count; i++)
{
Agency d = list[i];
d.isSelected = true;
}
}
當我打的全選按鈕,我希望複選框全部進行檢查。但沒有任何反應。