Reputation: 3887
I'm new to XAML, and maybe my question is a little bit stupid, but, here is my problem.
I have a ListView
, and i have set the ItemSource
to a ObservableList inside a ModelView class
Here's how my code looks like:
public class ListModelView
{
ObservableList<MyClass> _list = new ObservableList<MyClass>();
public ObservableList<MyClass> MyList { get{return _list;} set{}}
public ListModelView()
{
_list = methodThatReturnsAListFromAWebService;
}
}
Every thing works just fine. But how do I modify (add, delete) elements from MyList
. To get it work i've modified properties as static
, and it work. But i wonder if this is the right way to do it. Thank You.
Upvotes: 0
Views: 45
Reputation:
You can access it by giving your view model in XAML, like this:
<viewModel:YourViewModel x:Name="ViewModelName"/>
Now you'll be able to access it in the code behind.
For further reading i'd recommend Messenger
from MVVM light toolkit, you can communicate between your View Models using this class
Upvotes: 3
Reputation: 2956
Your MyList Set Property is empty.
public ObservableList<MyClass> MyList { get{return _list;} set{ _list=value;}}
Now you will be allowed to edit delete and add items to MyList
Upvotes: 0