c# - Listbox cannot display in WP8 Emulator -
it's wired. i'm developing wp8 app. xaml code is:
<phone:phoneapplicationpage x:class="wptestservice4dotnet.mainpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:microsoft.phone.controls;assembly=microsoft.phone" xmlns:shell="clr-namespace:microsoft.phone.shell;assembly=microsoft.phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d" fontfamily="{staticresource phonefontfamilynormal}" fontsize="{staticresource phonefontsizenormal}" foreground="{staticresource phoneforegroundbrush}" supportedorientations="portrait" orientation="portrait" shell:systemtray.isvisible="true"> <!--layoutroot root grid page content placed--> <grid x:name="layoutroot" background="transparent"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="*"/> </grid.rowdefinitions> <!--titlepanel contains name of application , page title--> <stackpanel x:name="titlepanel" grid.row="0" margin="12,17,0,28"> <textblock x:name="applicationtitle" text="my application" style="{staticresource phonetextnormalstyle}" margin="12,0"/> <textblock x:name="pagetitle" margin="9,-7,0,0" style="{staticresource phonetextnormalstyle}"/> </stackpanel> <!--contentpanel - place additional content here--> <grid x:name="contentpanel" grid.row="1" margin="12,0,12,0"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="*"/> </grid.rowdefinitions> <textblock grid.row="0" text="avatar" fontsize="18"></textblock> <listbox grid.row="1" x:name="resultbox" borderbrush="bisque" borderthickness="4" datacontext="{binding}"> <listbox.itemtemplate> <datatemplate> <stackpanel> <textblock text="inner display" fontsize="18"></textblock> <textblock text="{binding path=id}" fontsize="18" fontstyle="italic" textwrapping="wrap"></textblock> <textblock text="{binding path=title}" fontsize="18" textwrapping="wrap"></textblock> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox> </grid> </grid> </phone:phoneapplicationpage>
and cs code is:
public partial class mainpage : phoneapplicationpage { // constructor public mainpage() { initializecomponent(); var results = new list<result>(); results.add(new result() { id = "1", title = "first" }); results.add(new result() { id = "2", title = "second" }); results.add(new result() { id = "3", title = "third" }); this.datacontext = results; // sample code localize applicationbar //buildlocalizedapplicationbar(); } public class result { public string id { set; get; } public string title { set; get; } } }
content in listbox doesn't display in windows phone 8 emulator. guess no error in code it's simple , dont' know why
it's itemssource determines output <listbox.itemtemplate>
this.resultbox.itemssource = results;
generally set datacontext viewmodel, itemssource collection/list inside viewmodel.
Comments
Post a Comment