j0ey_wh j0ey_wh - 1 month ago 6x
C# Question

Using the binded object C#/XAML

I'm new to XAML, and maybe my question is a little bit stupid, but, here is my problem.

I have a

, and i have set the
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
. To get it work i've modified properties as
, and it work. But i wonder if this is the right way to do it. Thank You.

Alx Alx

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