Relative Source Binding Xamarin

后端 未结 1 1571
温柔的废话
温柔的废话 2021-01-06 16:42

My problem is with the viewcell, the OnDelete command is not found due to it being of the IssueModel class, I\'ve attempted to change the binding-context of the Listview, bu

1条回答
  •  温柔的废话
    2021-01-06 17:02

    Add a x:Name attribute to your freshMvvm:FreshBaseContentPage, like i.e.: x:Name="MyAwesomePage".

    Now change your ViewCell binding like this:

    
    

    Now the binding source is set to the page by using its name. And the path is set to the property BindingContext.OnDelete. So, in your backing view model for this page there should be a OnDelete property.

    To clarify the separate components like you've asked in the comments.

    The Path= is omitted with a regular binding. When not explicitly mentioned, {Binding MyProperty} means the same as '{Binding Path=MyProperty}'. Path means the path to the value that needs to be bound from the BindingContext, so effectively the property that you are binding to.

    The Source is used to specify what is the source of the Path. Which is in itself another binding. In our case to a reference which is known by the name we just gave the page. This way, the binding of the ViewCell knows to start at the Source and then search for the Path to retrieve its value. I hope this makes it a bit clear.

    You can reference anything here if you want to, as long as you have access to the instance of the class here. I would, however, recommend to keep it to the BindingContext which is effectively the view model (note: BindingContext is the actual property of your page that contains the view model). Else you will lose overview very quickly.

    0 讨论(0)
提交回复
热议问题