问题描述
被GOOGLE了很多后,终于我要问这对你们。结果
我心中已经创建的的ScrollViewer
,其中包含项目( listboxItems
),这些项目从 Web服务
获取。但一次只有5个项目可以取出。所以最初这将是5个项目,那么未来5(附加到的ScrollViewer
),然后接下来的5等等......
请注意:尤其是圆形 listBoxitems
在里面的的ScrollViewer
,而不是列表框
数据 Web服务牵强
还包含 --- >
总笔数
numResults(项目目前有多少进账)
现在假设我的方法来获取数据是--->
的getData(INT nextResult)
{
//一些代码来获取数据
}
其中nextResult为下一个项目编号(例如: - nextResult是6,如果请求第二次)
但我不能写代码来检测用户的滚动的ScrollViewer到结束放大器;然后调用一个方法或解雇,不管说的!
我心中已经被ScrollViewer中的中严重混淆 VerticalOffset
, ExtentHeight
, ViewportHeight
, ScrollableHeight
等,有关使用它们和放大器;计算所需的信息,以达到上述要求。
所以如果有人知道的相同或使用过scrollviwer,比请张贴的答案。
我通过与相应的事件注册新的DependencyProperty ListVerticalOffset做到了这一点:
//构造
公众的MainPage()
{
的InitializeComponent();
ListVerticalOffsetProperty = DependencyProperty.Register(ListVerticalOffset的typeof(双),typeof运算(的MainPage),新PropertyMetadata(OnListVerticalOffsetChanged));
YourScrollViewer.Loaded + = YourScrollViewer_Loaded;
}
无效YourScrollViewer_Loaded(对象发件人,RoutedEventArgs E)
{
无功约束力=新的Binding
{
来源= YourScrollViewer,
路径=新的PropertyPath(VerticalOffset),
模式= BindingMode.OneWay
};
SetBinding(ListVerticalOffsetProperty,绑定);
}
私人无效OnListVerticalOffsetChanged(OBJ的DependencyObject,DependencyPropertyChangedEventArgs E)
{
VAR atBottom = YourScrollViewer.VerticalOffset> = YourScrollViewer.ScrollableHeight;
如果(atBottom)MessageBox.Show(结束);
}
公共只读的DependencyProperty ListVerticalOffsetProperty;
公共双ListVerticalOffset
{
{返回(双)的GetValue(ListVerticalOffsetProperty); }
集合{的SetValue(ListVerticalOffsetProperty,值); }
}
可能是该解决方案或它的实现是不是最佳的,但它的工作我的。
after being googled a lot, finally i am going to ask this to you guys.
i'v created scrollviewer
, which contains items(listboxItems
) and these items fetching from the webservices
. but at once only 5 items can fetched. so initially it'll be 5 items, then next 5(appended to the scrollviewer
) and then next 5 and so on......
note:-here listBoxitems
are used inside the scrollviewer
, not the listbox
data fetched from webservice
also contains--->
total items
numResults (current number of items fetched)
now suppose my method to fetch data is--->
getData(int nextResult)
{
// some code to fetch the data
}
where nextResult is next item number(ex:- nextResult is 6, if requesting 2nd time)
but i am unable to write the code to detect that the user scrolled the scrollviewer to the end & then a method to be called or fired, whatever say!
i'v been badly confused among scrollviewer's VerticalOffset
, ExtentHeight
, ViewportHeight
, ScrollableHeight
etc, about to use them & calculate desired information to achieve above requirements.
so if anyone knows about the same or used ever scrollviwer, than please post answer.
I achieved it by registering new DependencyProperty ListVerticalOffset with appropriate event:
// Constructor
public MainPage()
{
InitializeComponent();
ListVerticalOffsetProperty = DependencyProperty.Register("ListVerticalOffset", typeof(double), typeof(MainPage), new PropertyMetadata(OnListVerticalOffsetChanged));
YourScrollViewer.Loaded += YourScrollViewer_Loaded;
}
void YourScrollViewer_Loaded(object sender, RoutedEventArgs e)
{
var binding = new Binding
{
Source = YourScrollViewer,
Path = new PropertyPath("VerticalOffset"),
Mode = BindingMode.OneWay
};
SetBinding(ListVerticalOffsetProperty, binding);
}
private void OnListVerticalOffsetChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var atBottom = YourScrollViewer.VerticalOffset >= YourScrollViewer.ScrollableHeight;
if (atBottom) MessageBox.Show("End");
}
public readonly DependencyProperty ListVerticalOffsetProperty;
public double ListVerticalOffset
{
get { return (double)GetValue(ListVerticalOffsetProperty); }
set { SetValue(ListVerticalOffsetProperty, value); }
}
May be this solution or it's realization is not optimal, but it's working for me.
这篇关于火(通话)方法,当ScrollViewer中滚动到结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!