简体   繁体   中英

WP8 longlist selector PullToRefresh and null viewport

I'm trying to implement PullToRefresh on my longlistselector . I've wrote my code with the help of posts like this and this

the problem is that the compression event handler is called whenever I scroll up or down, regardless whether I've reached the top or bottom of list or not. By doing more search, I've found that my solution lays with viewportcontrol which is a child element of longlistselector . I tried getting this viewportcontrol using the VisualTreeHelper :

_viewport = FindVisualChild<ViewportControl>(listbox);

and by FindName :

_viewport  = this.FindName("ViewportControl") as ViewportControl;

but it's always returning null. Does anyone know what I'm doing wrong here?

I've solved my problem by creating a custom longlistselector and overriding the OnApplyTemplate method:

public class MyLongListSelector : LongListSelector
    {
        public ViewportControl ViewportControl { get; private set; }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ViewportControl = (ViewportControl)GetTemplateChild("ViewportControl");
        }
    }

Hope this helps anyone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM