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
Post a Comment