dimanche 19 avril 2015

Get Checked CheckBoxes from a StackPanel in Windows Phone 8.1

I'm trying to get the selected Checkboxes from a Button trigger and it's giving me only null values. What am I doing wrong and how to fix this? This is in Windows Phone 8.1



<ScrollViewer Margin="10,181,10,78">
<StackPanel x:Name="boxesPanel">
<CheckBox Content="Colombo"/>
<CheckBox Content="Galle" />
<CheckBox Content="Kandy" />
<CheckBox Content="Polonnaruwa" />
<CheckBox Content="Sigiriya" />
<CheckBox Content="Anuradhapura" />
<CheckBox Content="Jaffna" />
<CheckBox Content="Haputale" />
<CheckBox Content="Pottuvil" />
<CheckBox Content="Bentota" />
<CheckBox Content="Katharagama" />
<CheckBox Content="Nuwara Eliya" />
</StackPanel>
</ScrollViewer>



private void nextButton_Click(object sender, RoutedEventArgs e)
{
List<String> locations = new List<String>();
for (int x = 0; x < boxesPanel.Children.Count; x++)
{
CheckBox temp = (CheckBox) boxesPanel.Children.ElementAt(x);
if ((bool)temp.IsChecked)
{
//locations.Add(temp.Name);
Debug.WriteLine(temp.Name);
}

}
trip.Locations = locations;
Frame.Navigate(typeof(Duration), trip);
}


Why is the null values coming? How to get the Names from the check boxes? Thanks in advance! :)





Aucun commentaire:

Enregistrer un commentaire