本文介绍了有关详细信息,请检查内部异常.将数据绑定到LongListSelector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从MySQL获取数据并将其绑定到longlistselector.当我运行该应用程序时,它捕获到错误操作期间发生异常,从而使结果无效".检查innerException以获取详细信息".可能是概率

I am fetching data from MySQL and bind it to a longlistselector. When I run the application, it catches the error "An exception occurred during the operation, making the result invalid. Check innerException for Details" What could be the prob

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 ex)
            {
               // MessageBox.Show("Check Your Internet Connectivity and try again later.\n No Network Connection", "Network Error!", MessageBoxButton.OK);
                MessageBox.Show(ex.Message);

            }
        }


是我的代码吗?


lem with my code?

推荐答案

如果以Debug模式运行,则在发生异常时,您应该能够打开异常框并深入到堆栈中以获取详细信息.

If running in Debug mode, when the exception occurs you should be able to open the exception box and drill down into the stack for details.

但是我怀疑问题是由于尝试在未在Dispatcher线程中运行时尝试在其中更新可视UI元素所致.考虑将您的"for"包装为内循环 Dispatcher.BeginInvoke().

But I suspect that the problem is due to attempting to update a visual UI element in while not running in the Dispatcher thread. Consider wrapping your "for" loop insideDispatcher.BeginInvoke().

希望这会有所帮助,
标记

Hope this helps,
Mark


这篇关于有关详细信息,请检查内部异常.将数据绑定到LongListSelector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 15:25