-1
나는 ListBox를 가지고 있습니다. 모든 ListBoxItem에는 두 개의 TextBlock과 하나의 CheckBox가 있습니다. 처음에는 모든 확인란을 선택했습니다. 하나의 체크 박스를 선택 해제 한 다음 스크롤하면 체크 박스가 무작위로 선택 및 선택 해제됩니다.목록 상자 항목의 체크 박스가 무작위로 선택/선택 해제되었습니다.
무엇이 잘못 되었나요?
코드 :
cut from [X.xaml.cs]
//
lbx.ItemsSource = settings.itemSettings; // settings is instance of Settings
// holds data for the listbox
public class Settings
{
public ObservableCollection<ItemSetting> itemSettings; // <-lbx.ItemSource
public Settings(ObservableCollection<string> texts)
{
itemSettings = new ObservableCollection<ItemSetting>();
for (int i = 0; i < texts.Count; i++)
{
ItemSetting s = new ItemSetting();
s.number = (i + 1).ToString(); // the position number
s.text = texts[i]; // the message
s.show = true; // true=show or false=hide
itemSettings.Add(s);
}
}
}
// holds data for listbox item
public class ItemSetting
{
public string number { get; set; }
public string text { get; set; }
public bool show { get; set; }
}
------------------------------------------------------------------------------
cut from [X.xaml] --- the listbox
<ListBox Name="lbx">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding number}" />
<TextBlock Text="{Binding text}" />
<CheckBox IsChecked="{Binding show}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>