xamarin - How do I read a view's bounds in the OnAppearing() method? -
currently have this:
protected override void onappearing() { var collapsedheight = reportformbuttonbar.height; var reportformexpandedposition = reportform.bounds; var reportformcollapsedposition = reportform.bounds; reportformcollapsedposition.y = ( reportform.height - collapsedheight ); reportformexpandedposition.y = 0; reportform.translateto( reportformcollapsedposition.x, reportformcollapsedposition.y, 200, easing.cubicout ); base.onappearing(); }
which supposed position reportform in collapsed position. that, need read bounds. however, bounds set x:0, y:0 width , height -1. i've been struggling long while , can't find answer.
tldr: should able read correct bounds in method? or there other way accomplish view setup?
to work view bounds, recommend overriding onsizeallocated
or sizechanged
event.
//in view class protected override void onsizeallocated(double width, double height) { base.onsizeallocated(width, height); // retreive view bounds here.. } //or.. reportform.sizechanged += (sender, e) => { if(width > 0 && height > 0) { // retreive view bounds here.. } };
Comments
Post a Comment