Creating Mobile Apps with Xamarin.Forms, Preview Edition (Developer Reference) by Petzold Charles

Creating Mobile Apps with Xamarin.Forms, Preview Edition (Developer Reference) by Petzold Charles

Author:Petzold, Charles [Petzold, Charles]
Language: eng
Format: epub, mobi
Publisher: Pearson Education
Published: 2014-09-25T21:00:00+00:00


editor.BindingContext = note;

editor.SetBinding(Editor.TextProperty, "Text");

Internally, these four statements result in similar event handlers being set. That’s how the data-binding mechanism works.

However, these four statements can actually be reduced to three statements. Here’s how:

The BindingContext property has a very special characteristic. It is very likely that more than one data binding on a page has the same BindingContext. That is true for this little example. For this reason, the BindingContext property is propagated through the visual tree of a page. In other words, if you set the BindingContext on a page, it will propagate to all the views on that page except for those views that have their own BindingContext properties set to something else. You can set BindingContext on a StackLayout and it will propagate to all the children (and other descendants) of that StackLayout. The two BindingContext settings shown above can be replaced with one set on the page itself:

this.BindingContext = note;

These automated data bindings are part of the NoteTaker5Page class. Also, the handlers for the Load and Save buttons have become lambda functions, all the variables have been moved to the constructor, and the code is looking quite sleek at this point:

Click here to view code image

class NoteTaker5Page : ContentPage

{

static readonly string FILENAME = "test.note";



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.