silverlight - Keep same layout when orientation changes -


i have silverlight page have below appearance in portrait , landscape mode. essentially, there 3 images arranged in grid. big image spans 2 columns. when phone rotates, images rotate, overall layout not. small images remain close back/windows/search button , large image remains towards top of phone.

enter image description here

i have tried number of methods achieve effect, have proved unsatisfactory in 1 way or another. i'm hoping can point out i'm missing or, @ least, prevent else having waste 4 or 5 days coming same conclusion did. questions in bold:

  • the first thing tried applying rotatetransform layoutroot element , rotating -90 degrees whenever phone rotation changed landscape. had hard code height , width of layout root 800 , 400 instead of "auto" or gets drawn squished. solution worked, rotatetransform gets applied after page drawn. because drawn 400x800 image on 800x400 screen, top 200 , bottom 200 pixels aren't drawn. becomes obvious after it's rotated , (now)left , right portions missing. is there way force layout engine draw off screen pixels there after rotatetransform applied?

  • the next thing considered (but did not try) set page supportedorientations "portraitonly" , use accelerometer generate own "onorientationchanged" event , selectively rotate images 90 degrees when phone tilted landscape. determined bad idea because wrong in subtle way resulting in confusion when rotation didn't work quite same way in app in every other app. is there way have onorientationchanged event fire without automatically updating layout of grid contains elements? alternatively, there other hook can used detect phone orientation?

  • the last thing tried similar advice offered here: windows phone 7 applications - orientation change , here: http://blogs.msdn.com/b/ptorr/archive/2010/03/27/strategies-for-dealing-with-orientation-changes.aspx. solution seems bit brittle me because forces me change relative sizes of grid rows , columns in onorientationchanged event handler in xaml code. in portrait mode, first row set 5* , 2nd row set 2*. when switch landscape, rows need each set 1* , columns need set 5* , 2* respectively. alternatively, hard-code size of small images , set rows , columns auto, i'm still stuck hard coding something. since i've exhausted of other options, think solution i'm stuck with.

am missing anything, or way it?

you don't have hard code anything. need clever designing. develop applications multiple orientation support should come clever grid layout lets reposition objects way want without creating mess.

for situation consider layout:

 <grid x:name="layoutroot" background="transparent"> <grid.columndefinitions> <columndefinition width="3.5*" /> <columndefinition width="1.5*" /> <columndefinition width="2*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="2.5*"/> <rowdefinition height="1.5*" /> <rowdefinition height="1.5*" /> <rowdefinition height="2*"/> </grid.rowdefinitions> <!--titlepanel contains name of application , page title--> <stackpanel x:name="titlepanel" margin="12,17,0,28" grid.columnspan="3" grid.rowspan="3"></stackpanel> <image name="bigsmiley" margin="8" grid.rowspan="3" grid.columnspan="3" source="big.jpg" stretch="fill"/> <image name="smallsmiley1" grid.row="3" source="smiley.jpg" stretch="fill" margin="8"/> <image name="smallsmiley2" grid.row="3" grid.column="1" source="smiley.jpg" stretch="fill" margin="8" grid.columnspan="2" /> <!--contentpanel - place additional content here--> </grid> 

layout

and orientation changed method should like:

private void phoneapplicationpage_orientationchanged(object sender, orientationchangedeventargs e) { if ((e.orientation & pageorientation.portrait) == pageorientation.portrait) { grid.setrow(bigsmiley, 0); grid.setcolumn(bigsmiley, 0); grid.setcolumnspan(bigsmiley, 3); grid.setrowspan(bigsmiley, 3); grid.setrow(smallsmiley1, 3); grid.setcolumn(smallsmiley1, 0); grid.setcolumnspan(smallsmiley1, 1); grid.setrowspan(smallsmiley1, 1); grid.setrow(smallsmiley2, 3); grid.setcolumn(smallsmiley2, 1); grid.setcolumnspan(smallsmiley2, 2); grid.setrowspan(smallsmiley2, 1); } else { grid.setrow(bigsmiley, 0); grid.setcolumn(bigsmiley, 0); grid.setcolumnspan(bigsmiley, 2); grid.setrowspan(bigsmiley, 4); grid.setrow(smallsmiley1, 0); grid.setcolumn(smallsmiley1, 2); grid.setcolumnspan(smallsmiley1, 1); grid.setrowspan(smallsmiley1, 2); grid.setrow(smallsmiley2, 2); grid.setcolumn(smallsmiley2, 2); grid.setcolumnspan(smallsmiley2, 1); grid.setrowspan(smallsmiley2, 2); } } 

result: result

i hope solves issue. remember, there's better design makes problems go away! :)


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -