c# - Connect view with viewmodel to share an ObservableCollection -


i can't show in listbox object observablecollection. how it?

here elemental code:

c#

    public observablecollection<string> collection { get; set; } private void add(window window)     {             collection = new observablecollection<string>();             collection.add("first item");     } 

xaml

  <listbox itemssource="{binding collection, mode=twoway}"      horizontalalignment="left" height="100" margin="10,10,0,0" verticalalignment="top" width="100" /> 

you need initialize collection in view model's constructor, or call add() method constructor.

btw, add() method doesn't use parameter.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -