Passing data between view in xamarin forms using mvvm

前端 未结 2 1485
独厮守ぢ
独厮守ぢ 2020-12-21 17:47

I\'m trying to navigate between pages and bind data at same time.

This is what I have tried :

public ICommand GetIdeasCommand
{
    get
    {
              


        
2条回答
  •  青春惊慌失措
    2020-12-21 18:24

    Your understanding of BindingContext is lacking. Usually you bind a ViewModel to a BindingContext. What you're doing here

    this.BindingContext = new IdeasSinglePage(ideas); //the app breaks here

    doesn't make sense.

    You are passing as context the page you want to load ? Just delete this line completely. Since in your recent comments you said you didn't want a ViewModel to begin with, what you will do in your CodeBehind is:

    public partial class IdeasSinglePage : ContentPage
    {
      public IdeasSinglePage(List ideas)
      {
        InitializeComponent();
        listViewName.ItemsSource = ideas;
      }
    }
    

    And in your xml you give your listView a Name. You need this Name for referencing the list on code behind.

    Hope it helps

提交回复
热议问题