I have a MultiselectList Control (from SL toolkit) in which i have data template with a check box. This is the xaml code i have:
<toolkit:MultiselectList x:Name="BankMultiSelectList" ItemTemplate="{StaticResource CustomItemTemplate}"/>
and the data template:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="CustomItemTemplate">
<CheckBox x:Name="BankCheckBox" Content="{Binding Path=Name}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"/>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
The binding is becoming with members in the bank class which is the following:
public class Bank
{
public Bank() { }
public Bank(string name)
{
this.Name = name;
}
public string Name { get; set; }
public bool IsSelected { get; set; }
public List<Bank> GetBanks()
{
return new List<Bank>()
{
new Bank("Eurobank"),
new Bank("Millennium Bank"),
new Bank("Attica Bank"),
new Bank("Ταχυδρομικό Ταμιευτήριο"),
new Bank("Alpha Bank"),
new Bank("Τραπεζα Κύπρου"),
new Bank("Hellenic Bank"),
new Bank("Probank"),
new Bank("FBBank"),
new Bank("CitiBank"),
new Bank("Τραπεζα Πειραιώς"),
new Bank("HSBC Bank"),
new Bank("Εθνική Τράπεζα"),
new Bank("Εμπορική Τράπεζα"),
new Bank("Proton Bank"),
new Bank("Αγροτική Τράπεζα"),
new Bank("Γενική Τράπεζα"),
new Bank("Tbank"),
new Bank("Marfin Egnatia Bank"),
};
}
}
In the page load i i fill the ItemsSource of MultiselectList (called BankMultiSelectList) with data from the bank class:
Bank bank = new Bank();
BankMultiSelectList.ItemsSource = bank.GetBanks();
That creates a page with some checkboxes with their names bind from the class method. I want to create a “select all” button in application bar to select all checkboxes at once when i press. How can i iterate through all the checkbox controls of the page in order to, let’s say, set their IsChecked property to true? Thanks in advance for your help.
You could iterate over the elements in the UI and set their checked state. But a much better way to do this would be to set the state of your model and let the bindings do the work of updating the UI for your.
Bankclass to implementINotifyPropertyChanged, specifically on theIsSelectedproperty.IsSelected=true… and you’re done!