C# - WPF class get all resources and fill listbox -


i have class resource names. here code :

using system; using system.collections.generic; using system.collections.objectmodel; using system.linq; using system.text;  namespace helper {      public static class callresources     {          public static observablecollection<string> callallresources()         {             var properties = typeof(properties.resources).getproperties(       system.reflection.bindingflags.public | system.reflection.bindingflags.nonpublic |       system.reflection.bindingflags.instance | system.reflection.bindingflags.static);              observablecollection<string> col = new observablecollection<string>();             foreach (var propertyinfo in properties)             {                 var s = propertyinfo.name;                 if (s != "resourcemanager" && s != "culture")                 {                     col.add(s);                 }             }            return col;         }     } } 

in mainwindows.cs have code:

public observablecollection<string> resourceslistbox         {                         {                 return callresources.callallresources();             }         } 

if call resourceslistbox have 1 line in querylistbox.

and in mainwindow.xaml have not work :

 <listbox x:name="querylistbox" horizontalalignment="left" height="155" margin="18,10,0,0" selectionmode="single" verticalalignment="top" width="389"  itemssource="{binding path = resourceslistbox}" selectionchanged="listbox_selectionchanged"/> 

so first need make class static can call code behind without creating new instance.

secondly need return list or observablecollection in callallresources method , place names in list or observablecollection.

then can call method code behind , returns list or observablecollection of resource names.

callresources class:

public static class callresources   {      public static observablecollection<string> callallresources()     {       var properties = typeof(properties.resources).getproperties( system.reflection.bindingflags.public | system.reflection.bindingflags.nonpublic | system.reflection.bindingflags.instance | system.reflection.bindingflags.static);        observablecollection<string> col = new observablecollection<string>();       foreach (var propertyinfo in properties)       {         var s = propertyinfo.name;         if (s != "resourcemanager" && s != "culture")         {            col.add(s);          }       }       return col;     }   } 

code behind:

public observablecollection<string> resourceslistbox {     {     return callresources.callallresources();   } } 

xaml code:

<listbox x:name="listbox1" itemssource="{binding path=resourceslistbox}"/> 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -