c# - Programly scroll list box -


my problem have newslist box:

enter image description here

taping on item open aticle page full article.

so, when return on news page see list box before navigated article, want item used appear on top

1) changing index doesn't because must remain are.

i have tried:

if (currentarticle < newslistbox.selectedindex) {     var scrollviwer = getscrollviewer(newslistbox) scrollviewer;     if (scrollviwer != null)     {          scrollviwer.scrolltoverticaloffset(scrollviwer.verticaloffset + (newslistbox.selectedindex - currentarticle));     }     currentarticle = newslistbox.selectedindex; } else if (currentarticle == newslistbox.selectedindex) { } else {     var scrollviwer = getscrollviewer(newslistbox) scrollviewer;     if (scrollviwer != null)     {         scrollviwer.scrolltoverticaloffset(scrollviwer.verticaloffset - (currentarticle - newslistbox.selectedindex));     }     currentarticle = newslistbox.selectedindex; }  public static dependencyobject getscrollviewer(dependencyobject o) {     // return dependencyobject if scrollviewer     if (o scrollviewer)     { return o; }      (int = 0; < visualtreehelper.getchildrencount(o); i++)     {         var child = visualtreehelper.getchild(o, i);          var result = getscrollviewer(child);         if (result == null)         {             continue;         }         else         {             return result;         }     }     return null; } 

it works doesnt place element correctly on top if previous element wasn't correctly on top - impossible when user scrolling.

addition:

newslistbox.scrollintoview(newslistbox.items[5]); 

works fine, shows element on bottom, need on top.

addition 2:

this work fine:

newslistbox.scrollintoview(newslistbox.selectedindex+offset); 

i need calculate offset

i'm not sure you're trying scrollviewer, when need re-arrange order of items in ui container control such listbox, re-arrange order of items in data collection object bound control , items in control follow order.

you order them date (and time) @terasato suggested or move selected item first position in collection using insert method.

apologies if have missed point.

after reading question again, see line saying indices of collection objects must stay same. if mean cannot sort original collection, need sort collection copied original collection.

i allow user filter collection of objects while still keeping original collection of objects unchanged. have 2 choices; either create property of same type collection in code behind/view model , copy original collection that, or use xaml collectionviewsource object sort objects in ui.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -