Hi everyone.
I'm having hard time to make ListView to show my data.
I hope someone can show me the right path.
I have view model with Items property:
public class MainViewModel
{
public ObservableCollection<string> Items= new ObservableCollection<string> { "one", "two", "three", "Four", "Five" };
}
I have NavigationPage with the BindingContext property set to the view model during instantiation.
var viewModel = new MainViewModel();
var page = new NavigationPage(new TestPage())
{
Title = "Test",
BindingContext = viewModel
};
Now I want to bind ItemSource property of the ListView to the Items property of the view model passed as a BindingContext of the page like this:
<ListView ItemsSource="{Binding Path=Items}" />
But it seems like it doesn't work that way.
Whenever I set Items directly to BindingContext of the page and then bind ItemSource of the ListView like this:
var viewModel = new MainViewModel();
var page = new NavigationPage(new TestPage())
{
Title = "Test",
BindingContext = viewModel.Items
};
<ListView ItemsSource="{Binding .}" />
it works.
But I want to set view model once as BindingContext of the page and then bind ItemSource to its property.
What am i doing wrong?