c# - Xamarin Forms ListView for iOS: Always Show ScrollBar -




i have productlist of type observablecollection<product> product class given below:

public class product {     public int id { get; set; }     public string name { get; set; }     public string path { get; set; } } 

in xamarin forms ios application, have listview itemsource productlist. when number of products in productlist height of listview not enough show of them, additional items can reached scrolling listview. however, want scrollbar displayed when scrolling listview displayed always. possible or should try ui besides listviev able show scrollbar.

there solutions xamarin.android couldn't find effective solution ios app.

thank much...

as @cole commented, flashscrollindicators can show indicator short time.

so, have customize scroll indicator.

create custom renderer of listview , add custom scroll indicator, this:

    public class mylistviewrenderer : listviewrenderer     {         public uiview bar;         protected override void onelementchanged(elementchangedeventargs<listview> e)         {             base.onelementchanged(e);              //hide default scroll indicator.             control.showsverticalscrollindicator = false;               //set delegate             customscrolldelegate customscrolldelegate = new customscrolldelegate();             control.delegate = customscrolldelegate;              //create background view of custom indicator.             double frameheight = control.frame.size.height;             double framewidth = control.frame.size.width;              double barbackgroundwidth = 6;             double statusbarheight = 20;              uiview barbackgroundview = new uiview();             cgrect barbvrect = new cgrect(framewidth - barbackgroundwidth, statusbarheight, barbackgroundwidth, frameheight);             barbackgroundview.frame = barbvrect;             barbackgroundview.backgroundcolor = uicolor.gray;             barbackgroundview.layer.cornerradius = 2;             barbackgroundview.layer.maskstobounds = true;               //create bar of custom indicator.             bar = new uiview();             cgrect barrect = new cgrect(1, 0, 4, 0);             bar.frame = barrect;             bar.backgroundcolor = uicolor.black;             bar.layer.cornerradius = 2;             bar.layer.maskstobounds = true;              //add views superview of tableview.             barbackgroundview.addsubview(bar);             control.superview.addsubview(barbackgroundview);              //transfer bar view delegate.             customscrolldelegate.bar = bar;          }          public override void layoutsubviews()         {             base.layoutsubviews();             console.writeline("end of loading!!!");             double contentheight = control.contentsize.height;             double frameheight = control.frame.size.height;             double barheight = frameheight * frameheight / contentheight;               //reset bar height when table view finishes loading.             cgrect barrect = new cgrect(bar.frame.x, bar.frame.y, bar.frame.width, barheight);             bar.frame = barrect;         }      } 

implement scrolled delegate tracks scrolling action of scrollview. can update position of indicator in delegate.

    public class customscrolldelegate : uikit.uitableviewdelegate     {         public uiview bar;         double bary;          public override void scrolled(uiscrollview scrollview)         {             double y = scrollview.contentoffset.y;             double contentheight = scrollview.contentsize.height;             double frameheight = scrollview.frame.size.height;              double barheight = frameheight * frameheight / contentheight;             bary = y / (contentheight - frameheight) * (frameheight - barheight);              //cut bar height when on top.             if (bary < 0)             {                 barheight = barheight + bary;                 bary = 0;             }              //cut bar height when on bottom.             if (bary > (frameheight - barheight))             {                barheight = barheight - (bary - (frameheight - barheight));             }              //reset barview rect. let's move!!!             cgrect barrect = new cgrect(bar.frame.x, bary, bar.frame.width, barheight);             bar.frame = barrect;          }      } 

it works this:

enter image description here





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -