0

I would like to synchronize the UI thread with changes in a view (pivot item 1 active view) which is active when the changes begin and switch to non active state (User interaction like changing the pivot item from the pivot item 1 to pivot item 2) before finishing the changes.

The changes never happens and the view is restored as the point when switching from active to non active state.

The UI stack composed from

ScrollViewer

  • Grid
  • List view
  • Grid

The grid controls contains progress bars to handle refresh

    private async void scrollViewer_ViewChanged2(object sender, ScrollViewerViewChangedEventArgs e)
    {
        var listView = scrollViewer.GetDescendantsOfType<ListView>().FirstOrDefault();
        var context = DataContext as IMainStreamViewModel;

        if (e.IsIntermediate) return;
        var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

        if (Math.Abs(scrollViewer.VerticalOffset) < 0.01 && _isPullRefresh)
        {
            // Adding item the Observable collection that is the
            // the item source for the listview
            // The method just add element using the core dispatcher
            context.PullToRefreshInsertion_Top(dispatcher, listView);
        }
        else if (_scrollBar.Value >= _scrollBar.Maximum)
        {
            // same action but in bottom of the observable collection
            // The method just add element using the core dispatcher
            context.PullToRefreshAdd_Bottom(dispatcher, listView);
        }

        _isPullRefresh = false;
        // Set the current element to be displayed in the list view
        await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
            () => listView.ScrollIntoView(listView.SelectedItem));
        // Scroll to the the listview and hidding the progress control
        await Task.FromResult(scrollViewer.ChangeView(null, 60, null));

    }

Finally the element may be added but the scroll viewer dont reset his position and listview also

How to solve the sychronisation, i think the problem come from the IsActiveView state if the UI element is not in the ACTIVE VIEW it doesn't execute or skip the event.

UPDATE 1 :

The situation is as :

Pivot control that contain two pivot items :

  • Pivot item one contain :
  • ***Scrollviewer
  • ******Grid that contain a custom progress bar top refresh
  • ******ListView containing the data that user can see and interact with
  • ******Grid that contain a custom progress bar bottom refresh
  • Pivot item two contain some Richtextblock ...

When i'm doing the pull to refresh from the pivot item one and before the custom progress bar disappears do swipe to the next pivot item.

When i come back to the first pivot item, it was freezed at the state when i want to refresh and the top or bottom progress bar still visible.

I solved that by doing some trick and add some isVisible property in my view model and i fire the event whenever i'm in this pivot item i call updatelayout() and now it works.

I think the problem come from the fact when i'm doing swipe, the UI thread cancels all operations and start executing the operations attached to the active view this is why the update layout event for the first pivot item never fire.

  • I'm a bit confused with what you're asking. When you say "Active" and "Non-Active" state. Are you talking VisualStates, like enabled/disabled textboxes? Could you describe what it is you're trying to accomplish? Right now it sounds like you want when a user is changing from one pivot to another to be able to set the visual state of the pivot to "Inactive" while resetting the ScrollViewer inside of it to some height. – Nate Diamond Oct 15 '14 at 18:56
  • Active and non active is property from the listview.IsActiveView means if the listview is in the current viewport: – Naoufal Bentoumi Oct 15 '14 at 19:41
  • Ah, I think I see. So when switching to a new pivot, you want the ViewChanged event to fire before the switch happens. Is this correct? – Nate Diamond Oct 15 '14 at 19:45
  • It' nearly the case but the ViewChanged fires nevertheless the method scrollviewer.ChangeView in it's process fire the updateLayout for the all visual tree and i stop this by doing swipe.I update the post with more details and solution, feel free to ask for further informations – Naoufal Bentoumi Oct 15 '14 at 21:50

0 Answers0