im new windows dev c# , xaml. learning rob miles "blue book" win8 dev.
i keep getting error message , im stuck. please me out or give me pointers. have added comment @ block giving me trouble. thanks
using system.collections.generic; using windows.ui.xaml.controls; using windows.ui.xaml.navigation; using addingmachine; namespace addingmachine { public class customer { public string name { get; set;} public string address{ get; set;} public int id { get; set;} public customer(string inname, string inaddress, int inid) { name = inname; address = inaddress; id = inid; } } public class customers { public string name { get; set;} public list<customer> customerlist; public customers(string inname) { name = inname; customerlist = new list<customer>(); } customers mailcustomers = new customers("mail order customers"); private customers customerlist; public static customers maketestcustomers() { string[] firstnames = new string[] { "rob", "jim", "joe", "nigel", "sally", "tim" }; string[] lastsnames = new string[] { "smith", "jones", "bloggs", "miles", "wilkinson", "brown"}; customers result = new customers("test customers"); int id = 0; foreach (string lastname in lastsnames) { foreach (string firstname in firstnames) { //construct customer name string name = firstname + " " + lastname; //add new customer list result.customerlist.add(new customer(name, name + "'s house", id)); // increase id next customer id++; } } return result; // having problem. "customers" object keep showing error msg not exit in current context. customers = customers.maketestcustomers(); foreach (customer c in customers.customerlist) { textblock customerblock = new textblock(); customerblock.text = c.name; customersstackpanel.children.add(customerblock); //customers = customers.maketestcustomers(); customerlist.itemssource = customers.customerlist; //customerlist = customers.maketestcustomers(); } } } }
xaml
<page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:addingmachine" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:app1="using:addingmachine" xmlns:app11="using:app1" x:class="addingmachine.mainpage" mc:ignorable="d" background="{themeresource applicationpagebackgroundthemebrush}"> <!--<stackpanel x:name="customersstackpanel" horizontalalignment="left" margin="9,6,0,0" verticalalignment="top" scrollviewer.bringintoviewonfocuschange="true"/>--> <listbox name="customerlist" selectionchanged="customerlist_selectionchanged"> <listbox.itemtemplate> <datatemplate> <stackpanel x:name="customersstackpanel" horizontalalignment="left" margin="9,6,0,0" verticalalignment="top" scrollviewer.verticalscrollbarvisibility="auto" scrollviewer.horizontalscrollmode="auto"> <textblock text="{binding name}" style="{staticresource phonetextextralargestyle}"/> <textblock text="{binding address}" style="{staticresource phonetextextralargestyle}"/> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox> </page>
books can prone mistakes, copying directly out of book won't learn opposed trying things out on own. if there error in book, book wrong, not compiler. book isn't law, compiler is.
as actual problem, dcastro pointed out, have not declared variable called customers
. perhaps meant use customerlist
instead.
when find error, take few moments read through code , understand what's going on. error messages pretty clear on problem.
Comments
Post a Comment