xamarin - Is there a way to code a label and a switch in a ViewCell without using StackLayout? -
the application working on has labels , on right side switch. here's sample of xaml used achieve this:
<viewcell x:name="ss"> <stacklayout verticaloptions="centerandexpand" padding="20,0,20,0"> <stacklayout orientation="horizontal" verticaloptions="centerandexpand"> <stacklayout horizontaloptions="startandexpand" verticaloptions="center"> <local:labelbodyrendererclass text="show subcategory" yalign="center" xalign="center" /> </stacklayout> <stacklayout horizontaloptions="endandexpand" orientation="horizontal"> <switch x:name="ssswitch" toggled="ssswitch" verticaloptions="center" /> </stacklayout> </stacklayout> </stacklayout> </viewcell>
what find out if there more optimal way achieve this. settings page has many switch settings , seems there large number of elements.
does have simpler way achieve same functionality or should stick many stacklayout elements?
you can use built-in switchcell if want/need custom cell layout can use grid
instead of stacklayout
. it's more efficient , it's easier define layouts.
<viewcell x:name="ss"> <grid verticaloptions="centerandexpand" padding="20, 0"> <grid.columndefinitions> <columndefinition width="*" /> <columndefinition width="auto" /> </grid.columndefinitions> <local:labelbodyrendererclass horizontaloptions="startandexpand" text="show subcategory" yalign="center" xalign="center" /> <switch x:name="ssswitch" grid.column="1" toggled="ssswitch" verticaloptions="center" horizontaloptions="end" /> </grid> </viewcell>
using example: have 2-columns 1-row grid. first column custom control labelbodyrendererclass
, second column switch.
note can apply horizontal , vertical option right in ui control.
more grid
udpate
sure, can use switchcell
xaml use other cell.
<switchcell x:name="ss" text="{binding setting1text}" on="{binding setting1}" /> <switchcell text="{binding setting2text}" on="{binding setting2}" /> <switchcell text="{binding setting3text}" on="{binding setting3}" /> <switchcell text="{binding setting4text}" on="{binding setting4}" />
these samples using binding customcell can use name , set value code behind, although suggest use binding.
hope helps.-
Comments
Post a Comment