Beispiel #1
0
        private void treeFolders_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            try
            {
                FolderView fv = (FolderView)e.NewValue;
                view.SelectedFolder = fv;

                if (fv != null)
                {
                    view.SetMessage(null);
                    ShowMessage(null);
                    fv.MessageViews.Clear();
                    ShowStatus("Reading messages...");
                    Mouse.OverrideCursor = Cursors.Wait;

                    // Read messages on a background thread so we can keep the UI in sync
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            xstFile.ReadMessages(fv.Folder);
                            // We may be called on a background thread, so we need to dispatch this to the UI thread
                            Application.Current.Dispatcher.Invoke(new Action(() => fv.UpdateMessageViews()));
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Error reading messages");
                        }
                    })
                    // When loading completes, update the UI using the UI thread
                    .ContinueWith((task) =>
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            ShowStatus(null);
                            Mouse.OverrideCursor = null;
                        }));
                    });

                    // If there is no sort in effect, sort by date in descending order
                    SortMessages("Date", ListSortDirection.Descending, ifNoneAlready: true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Unexpected error reading messages");
            }
        }
        private void treeFolders_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            Folder f = (Folder)e.NewValue;

            view.SelectedFolder = f;

            if (f != null)
            {
                view.SetMessage(null);
                ShowMessage(null);
                f.Messages.Clear();
                ShowStatus("Reading messages...");
                Mouse.OverrideCursor = Cursors.Wait;

                // Read messages on a background thread so we can keep the UI in sync
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        xstFile.ReadMessages(f);
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error reading messages");
                    }
                })
                // When loading completes, update the UI using the UI thread
                .ContinueWith((task) =>
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        ShowStatus(null);
                        Mouse.OverrideCursor = null;
                    }));
                });

                // If there is no sort in effect, sort by date in descending order
                if (listViewSortCol == null)
                {
                    string tag = "Date";
                    listViewSortCol     = ((GridView)listMessages.View).Columns.Select(c => (GridViewColumnHeader)c.Header).Where(h => h.Tag.ToString() == tag).First();
                    listViewSortAdorner = new SortAdorner(listViewSortCol, ListSortDirection.Descending);
                    AdornerLayer.GetAdornerLayer(listViewSortCol).Add(listViewSortAdorner);
                    listMessages.Items.SortDescriptions.Add(new SortDescription(tag, ListSortDirection.Descending));
                }
            }
        }