How to check if data list binding is complete? (WP7)

I have a master control, where its element contains a list with elements. When I go to the next point of hinged data binding it takes some time, and I want to know when the data binding is completed, because I need to turn on the menu bar as soon as the ListBox is ready to appear. I could not find an event that could help me here. I tried the Loaded event from the list, but while it works for some elements, for some others it does not fire! I also tried updating the layout, but it starts too many times, and this cannot help me.

What can I do? thanks

+4
source share
1 answer

To ensure good performance when scrolling through rotation elements quickly, you need to wait to anchor the contents of the rotation element until the SelectedIndex changes. Thus, he will not try to communicate while the user quickly switches between Pivot elements; it will only be attached when you stop at the Pivot element.

Then you must set the ItemsSource ListBox property in the Pivot element in the LayoutUpdated event. I use the following extension method:

public static void InvokeOnLayoutUpdated(this FrameworkElement element, Action action) { if (element == null) { throw new ArgumentNullException("element"); } else if (action == null) { throw new ArgumentNullException("action"); } // Create an event handler that unhooks itself before calling the // action and then attach it to the LayoutUpdated event. EventHandler handler = null; handler = (s, e) => { element.LayoutUpdated -= handler; action(); }; element.LayoutUpdated += handler; } 

So then you will have code that looks something like this:

 pivot.InvokeOnLayoutUpdate(() => { Dispatcher.BeginInvoke(() => { list.ItemsSource = source; ApplicationBar.IsMenuEnabled = true; }); }); 
+1
source

Source: https://habr.com/ru/post/1335774/


All Articles