c# - How to Create ItemTemplate of ListPicker -
in following http://www.geekchamp.com/articles/listpicker-for-wp7-in-depth trying set listpicker populated using list of custom class type, reason not see items bound in view. have
mainpage.xaml
<grid.resources> <datatemplate x:name="searchprovideritemtemplate"> <stackpanel orientation="horizontal"> <image source="{binding favicon}" /> <textblock text="{binding name}" margin="12,0,0,0"/> </stackpanel> </datatemplate> <datatemplate x:name="searchproviderfullmodeitemtemplate"> <stackpanel orientation="horizontal"> <image source="{binding favicon}" /> <textblock text="{binding name}" margin="12,0,0,0"/> </stackpanel> </datatemplate> </grid.resources> ... <toolkit:listpicker x:name="searchproviderlistpicker" header="{binding path=localizedresources.settingspage_searchprovider, source={staticresource localizedstrings}}" itemtemplate="{binding searchprovideritemtemplate}" fullmodeheader="{binding path=localizedresources.settingspage_searchprovider, source={staticresource localizedstrings}}" fullmodeitemtemplate="{binding searchproviderfullmodeitemtemplate}" selectedindex="{binding}" selectionchanged="searchproviderlistpicker_selectionchanged" cachemode="bitmapcache"/>
mainpage.xaml.cs
list<listitem> searchproviderlist; public mainpage() { initializecomponent(); populatesearchproviderlist(); } private void populatesearchproviderlist() { searchproviderlist = new list<listitem>(); searchproviderlist.add(new listitem { favicon = "", name = "bing", address = "http://www.bing.com" }); searchproviderlist.add(new listitem { favicon = "", name = "google", address = "http://www.google.com" }); searchproviderlistpicker.itemssource = searchproviderlist; }
for reason see in listpicker testapp.classes.listitem
. class listitem
created following
listitem.cs
public string favicon { get; set; } public string name { get; set; } public string address { get; set; }
change this:
<toolkit:listpicker x:name="searchproviderlistpicker" header="{binding path=localizedresources.settingspage_searchprovider, source={staticresource localizedstrings}}" itemtemplate="{binding searchprovideritemtemplate}" fullmodeheader="{binding path=localizedresources.settingspage_searchprovider, source={staticresource localizedstrings}}" fullmodeitemtemplate="{binding searchproviderfullmodeitemtemplate}" selectedindex="{binding}" selectionchanged="searchproviderlistpicker_selectionchanged" cachemode="bitmapcache"/>
to this:
<toolkit:listpicker x:name="searchproviderlistpicker" header="{binding path=localizedresources.settingspage_searchprovider, source={staticresource localizedstrings}}" itemtemplate="{staticresource searchprovideritemtemplate}" fullmodeheader="{binding path=localizedresources.settingspage_searchprovider, source={staticresource localizedstrings}}" fullmodeitemtemplate="{staticresource searchproviderfullmodeitemtemplate}" selectedindex="{binding}" selectionchanged="searchproviderlistpicker_selectionchanged" cachemode="bitmapcache"/>
Comments
Post a Comment