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.