Exemplo n.º 1
0
 public static void ScrollToCenterOfView(this ItemsControl itemsControl, object item)
 {
     // Scroll immediately if possible
     if (!itemsControl.TryScrollToCenterOfView(item))
     {
         // Otherwise wait until everything is loaded, then scroll
         if (itemsControl is ListBox)
         {
             ((ListBox)itemsControl).ScrollIntoView(item);
         }
         itemsControl.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
         {
             itemsControl.TryScrollToCenterOfView(item);
         }));
     }
 }