-2

选择所有意味着重命名所有复选框被选中。我的代码如下:

<ListBox  Name="VillageList">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <CheckBox IsChecked="{Binding isCheched}"  Content="{Binding Villages}"  IsChecked="False"/>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

所以所有复选框都在列表框内。如何检查为所有复选框单选启用。

public class  villageinformation
{
    public string Villages{get;set;}
    public bool isChecked {get;set;}
}

page.cs{

list<villageinformation> mydataSource=new list<villageinformation>();
myDataSource.Add(new villageinformation(){Village="All",isChecked ="False"});
myDataSource.Add(new villageinformation(){Village="name1",isChecked ="False"});
myDataSource.Add(new villageinformation(){Village="name2",isChecked ="False"});
myDataSource.Add(new villageinformation(){Village="name3",isChecked ="False"});


VillageList.itemSource=myDataSource;
}

因此,在手动单击“全部”复选框时,剩余的 name1、2、3 被选中了怎么做?

4

1 回答 1

0

If you are using the ObservableCollection for your villages list, which is used for the data binding to the ListBox, then you can set all values in the ObservalbeCollection in the codebehind which shoul update the UI (by checking all the Checkboxes)

you can do it something like this

foreach(var village in VillagesCollection)
{
  village.isChecked = true;
}

If you are not able to understand the above, edit your question with how you are setting up the Village data in the code behind file (means .xaml.cs file)

于 2013-03-07T10:04:24.173 回答