I have been studying databinding techniques in numerous different WPF/MVVM resources. I thought I had a fairly strong grasp on the purpose and use of the DataContext
object. But then I came across this article on MVVM (this is a .pdf which was referenced here). The entire chapter doesn't mention DataContext once, but instead utilizes "BindingContext" objects on various content controls. I have never heard of a BindingContext
before; is it unique to Xamarin forms or something? Is it an alternate but equivalent way to set up the DataContext for a control?
UPDATE:
While my question in this regard has been answered below, it turns out that I'm not the only one confused by differences such as these. Apparently, the history behind the development of Xamarin.Forms has led to numerous discrepancies with Windows XAML. I am glad to learn that a formal effort to standardize these two paths has just been announced and will include the DataContext terminology.
The DataContext is the source of all entities mapped over a database connection. It tracks changes that you made to all retrieved entities and maintains an "identity cache" that guarantees that entities retrieved more than one time are represented by using the same object instance.
The BindingContext property indicates the binding source, which is the Slider . The SetBinding method is called on the binding target but specifies both the target property and the source property. The target property is specified as a BindableProperty object: Label.
Every FrameworkElement can be associated with a DataContext which will be used as the default data source during binding, if no other data source is specified in the binding code. Also, the children of this FrameworkElement auotmatically inherit this setting.
Yes; a BindingContext
in Xamarin is equivalent to a DataContext
in WPF.
There are also BindingContext
's in WinForms and ASP.NET but those work differently. You may want to see this blog post for more: http://blog.galasoft.ch/posts/2014/07/using-xamarin-forms-with-mvvmlight/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With