private async void CityList_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { int index = CityList.SelectedIndex; if (index == -1) { return; } ListBox listBox = sender as ListBox; City city = null; if (listBox.Tag is State) { State state = listBox.Tag as State; city = state._cities[index]; } if (listBox.Tag is SubContinent) { SubContinent subContinent = listBox.Tag as SubContinent; city = subContinent._stateOrCityList[index] as City; } await SampleDataSource.ChangeCity(city._UrlToken); // Use the navigation frame to return to the previous page itemDetailPage.UpdateTitle(); if (this.Frame != null && this.Frame.CanGoBack) { this.Frame.GoBack(); } }
private void StateList_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { int index = StateList.SelectedIndex; // ignore invalid index (caused by items.clear() below) if (index == -1) { return; } ListBox listBox = sender as ListBox; SubContinent subContinent = listBox.Tag as SubContinent; StateOrCity stateOrCity = subContinent._stateOrCityList[index]; State state = stateOrCity as State; // StateList.Items.Clear(); CityList.Items.Clear(); CityList.Tag = state; foreach (City city in state._cities) { ListBoxItem item = new ListBoxItem(); TextBlock textBlock = new TextBlock(); item.Content = textBlock; textBlock.Text = city._Name; CityList.Items.Add(item); CityScroller.Visibility = Visibility.Visible; } }
private void SubContinentList_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { int index = SubContinentList.SelectedIndex; if (index == -1) { return; } SubContinent[] subContinents = Calender2.Data.CityData.GetCityData(); SubContinent subContinent = subContinents[index]; ListBox listBoxToUse; ScrollViewer scrollerToUse; if (subContinent._stateOrCityList[0] is State) { listBoxToUse = StateList; scrollerToUse = StateScroller; } else { // Hide state list StateScroller.Visibility = Visibility.Collapsed; listBoxToUse = CityList; scrollerToUse = CityScroller; } listBoxToUse.Items.Clear(); listBoxToUse.Tag = subContinent; foreach (StateOrCity stateOrCity in subContinent._stateOrCityList) { ListBoxItem item = new ListBoxItem(); TextBlock textBlock = new TextBlock(); item.Content = textBlock; textBlock.Text = stateOrCity._Name; listBoxToUse.Items.Add(item); } scrollerToUse.Visibility = Visibility.Visible; }