gpt4 book ai didi

windows - 在 Windows Phone 8 中从 MySQL 数据库绑定(bind) LongListSelector 中的字符串

转载 作者:可可西里 更新时间:2023-11-01 10:48:08 29 4
gpt4 key购买 nike

在使用 LongListSelector 时,我是 Windows Phone 8 esp 的新手。我正在尝试从 MySQL 数据库中获取一个列表并将其绑定(bind)到 LongListSelector 中。在我的代码中,它只显示 MessageBox 对话框而不是获取列表。可能是什么问题呢。或者我是否以错误的方法放置了用于获取列表的代码。请帮助..

要绑定(bind)到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);

}
}

最佳答案

据我了解,您正在尝试为每个列表项显示一个字符?

如果是,我建议将 foreach 循环替换为:

ListCompanies.ItemsSource = f1;

如果你想显示最终列表中的每个字符串,每个项目一个字符串:

ListCompanies.ItemsSource = final;

您遇到了未实现的异常,因为 ItemsSource 属性被指定给您创建的列表。

关于windows - 在 Windows Phone 8 中从 MySQL 数据库绑定(bind) LongListSelector 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15346674/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com