c# - Set ListView ItemSource Binding in Code Behind Xamarin Forms -


i can't seem straight answer problem. im trying set item source in code behind. easy in xaml seems not straight forward in code behind.

in code behind using:

binding listbind = new binding("routelabels") {source=this};  listviewofroutes.itemssource = setbinding(listview.itemssourceproperty, listbind); 

this throws error of "cant convert void system.collections.ienumerable" think isn't correct.

im trying bind observable collection in view model.

the view model:

private observablecollection<routeinfo> _routelabels;     public observablecollection<routeinfo> routelabels     {         { return _routelabels; }         set         {             if (equals(value, _routelabels)) return;             _routelabels = value;             onpropertychanged(nameof(routelabels));          }     } 

when setting binding in xaml binding works fine. issue not observable collection issue have no idea how set binding in code behind.

summary:

i need know how (itemsource binding):

<listview x:name="listviewofroutes" itemssource="{binding routelabels}">   </listview> 

in code behind.

any appreciated.

to programmatically set binding on control, have pass parameter in extension method. reference links: extension methods, or member method

for example, try:

listviewofroutes.setbinding(listview.itemssourceproperty, "routelabels") //or,  listviewofroutes.setbinding(listview.itemssourceproperty, new binding("routelabels"))  

this sets binding between path 'routelabels' , control's bindingcontext view model.

also, recommend changing 'routelabels' 'routelabels' per standard naming policy c# properties.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -