How to display a dictionary of items in a Listbox on Windows Phone, using C#? -


in here opened word/definition text file. , trimmed putting word newword , definition newdefn. placed in dictionary, created follows:

dictionary<string, string> d = new dictionary<string, string>();

which declared global. since inside while(!endofstream) loop, words , definitions stored there.

my problem how put values in dictionary listbox. code:

    public search()     {         initializecomponent();                                         stream txtstream = application.getresourcestream(new             uri("/panoramaapp1;component/word.txt", urikind.relative)).stream;          using (streamreader sr = new streamreader(txtstream))         {             string jon;              //definition.text = sr.readtoend();               while (!sr.endofstream)             {                 jon = sr.readline();                    newword = (word.trim(new char[] { '-',' ' }));                 newdefn = (defn.trim(new char[] { '-',' ' }));                                   d.add(newword, newdefn);                                               }         }                          } 

i want search in textbox , results displayed in listbox. have problem part in "textbox selection changed". i'm getting error in listbox.items.add(str);

 list<string> list = new list<string>(d.keys);   foreach (string str in list)  {      if (str.startswith(searchbox.text,              stringcomparison.currentcultureignorecase))      {          listbox.items.add(str);      }  } 

you have set dictionary itemssource property of listbox:

yourlistbox.itemssource = d; 

you can customize how want show items using datatemplate items. example show word:

<listbox  name="yourlistbox" >     <listbox.itemtemplate>         <datatemplate>             <textblock text="{binding key}" tap="item_tap" />         </datatemplate>     </listbox.itemtemplate> </listbox> 

and show definition in messagebox when item tapped, can following in event handler:

private void item_tap(object sender, system.windows.input.gestureeventargs e) {     var s = sender textblock;     messagebox.show(d[s.text]); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -