C# Xaml ListBox Template Add in c# -
i did research listbox didnt understand how solve problem. have listbox in xaml page , want add listviewitem using template (so toggle button , on) not in xaml , of c#. how do this? thx help
<listbox x:name="listbox" background="red"> <listbox.itemtemplate > <datatemplate> <grid x:name="templategrid"> <toggleswitch x:name="toggle" foreground="black"> <toggleswitch.background> <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0"> <gradientstop color="black" offset="0"/> <gradientstop color="black" offset="1"/> </lineargradientbrush> </toggleswitch.background> </toggleswitch> <textblock horizontalalignment="right" verticalalignment="center" width="26" x:name="text" foreground="black">test</textblock> </grid> </datatemplate> </listbox.itemtemplate>
the listbox use template automatically. code, call listbox.items.add(obj). 1 thing note though - in data template don't see specifying datatype data template target, use generic display calling tostring() on object.
Comments
Post a Comment