Monday, December 31, 2012

Windows Phone ListBox Flicking Behaviour

Windows Phone ListBox Flicking Behaviour

All

While scrolling the ListBox to the top, if I still hold my fingure down, the listbox will be compressed a liitle bit but it will flick back as normal while I released the tap. Is it any way to detect this behaviour?

Currently I'm using this code to catch the scroll event, but while the listbox reach the top or the end, the values will always be 0 or as the listbox's heigh even if I do the gesture as above descibed.

void PageLoaded(object sender, RoutedEventArgs e)     {         List<ScrollBar> scrollBarList = GetVisualChildCollection<ScrollBar>(listBox1);         foreach (ScrollBar scrollBar in scrollBarList)         {             if (scrollBar.Orientation == System.Windows.Controls.Orientation.Horizontal)             {                 scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(horizontalScrollBar_ValueChanged);             }             else             {                 scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(verticalScrollBar_ValueChanged);             }         }           }      private void horizontalScrollBar_ValueChanged(object sender, RoutedEventArgs e)     {      }      private void verticalScrollBar_ValueChanged(object sender, RoutedEventArgs e)     {         ScrollBar scrollBar = (ScrollBar)sender;         object valueObj = scrollBar.GetValue(ScrollBar.ValueProperty);         object maxObj = scrollBar.GetValue(ScrollBar.MaximumProperty);         if (valueObj != null && maxObj !=null)         {             double value = (double)valueObj;             double max = (double)maxObj;              System.Diagnostics.Debug.WriteLine(value);             System.Diagnostics.Debug.WriteLine(max);         }     }      void btnDelete_Click(object sender, EventArgs e)     {         ((ObservableCollection<String>)listBox1.ItemsSource).Remove("hello1");         listBox1.ScrollIntoView(listBox1.Items[listBox1.Items.Count()-1]);     }      public static List<T> GetVisualChildCollection<T>(object parent) where T : UIElement     {         List<T> visualCollection = new List<T>();         GetVisualChildCollection(parent as DependencyObject, visualCollection);         return visualCollection;     }     private static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : UIElement     {         int count = VisualTreeHelper.GetChildrenCount(parent);         for (int i = 0; i < count; i++)         {             DependencyObject child = VisualTreeHelper.GetChild(parent, i);             if (child is T)             {                 visualCollection.Add(child as T);             }             else if (child != null)             {                 GetVisualChildCollection(child, visualCollection);             }         }     } 

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog