全て
ListBox を一番上までスクロールしているときに指を押したままにすると、リストボックスが少し圧縮されますが、タップを放すと通常どおりにフリックします。この動作を検出する方法はありますか?
現在、このコードを使用してスクロールイベントをキャッチしていますが、リストボックスが一番上または最後に到達している間、上記のようにジェスチャを行っても、値は常に0またはリストボックスの高さになります。
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);
}
}
}