在使用 LongListSelector 时,我是 Windows phone 8 的新手。我正在尝试从 MySQL 数据库中获取列表并将其绑定到 LongListSelector 中。在我的代码中,它只显示 MessageBox 对话框而不是获取列表。可能是什么问题呢。或者我是否将用于获取列表的代码放在了错误的方法中。请帮忙..
要绑定到 LongListSelector 的字符串是 f1,ListLongselector name= ListCompanies
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Set the data context of the LongListSelector control to the sample data
DataContext = App.ViewModel;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
// Load data for the ViewModel Items
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//if (!App.ViewModel.IsDataLoaded)
//{
// App.ViewModel.LoadData();
//}
string url = "http://localhost/taxi/fetch_nrb.php";
WebClient webclientmenu = new WebClient();
webclientmenu.DownloadStringCompleted += webclientmenu_DownloadStringCompleted;
webclientmenu.DownloadStringAsync(new Uri(url));
}
// Handle selection changed on LongListSelector
private void MainLongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//// If selected item is null (no selection) do nothing
//if (MainLongListSelector.SelectedItem == null)
// return;
//// Navigate to the new page
//NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + (MainLongListSelector.SelectedItem as ItemViewModel).ID, UriKind.Relative));
//// Reset selected item to null (no selection)
//MainLongListSelector.SelectedItem = null;
}
void webclientmenu_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//throw new NotImplementedException();
try
{
string list = e.Result;
string[] final = list.Split('#');
string f1 = final[0];
for (int i = 0; i < f1.Length; i++)
{
ListCompanies.ItemsSource.Add(f1[i]);
}
}
catch (Exception)
{
MessageBox.Show("Check Your Internet Connectivity and try again later.\n No Network Connection", "Network Error!", MessageBoxButton.OK);
}
}