Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Native Bindings#278

Merged
jassmith merged 2 commits intomasterfrom
sdx-nativeBindings2
Sep 8, 2016
Merged

Native Bindings#278
jassmith merged 2 commits intomasterfrom
sdx-nativeBindings2

Conversation

@StephaneDelcroix
Copy link
Copy Markdown
Member

@StephaneDelcroix StephaneDelcroix commented Aug 4, 2016

Description of Change

Allow binding to Native (non-BP) Views.

Each platform now expose SetBinding(string propertyName, BindingBase binding) as an extension method on the respective native views (UIView, Android.View, FrameworkElement).

To get 2-Way Bindings to work, SetBinding can take an additional updateSourceEventName argument. On iOS, if the Property of the UIView is Observable, the updateSourceEventName is not mandatory. On [U]WP, something similar is done in order to try to get 2-Way bindings to behave even without the updateSourceEventName.

In addition to this, the platforms also expose SetValue(BindableProperty property, ...) and SetBinding(BindableProperty property, ...). Those will have no effect unless the view happen to be directly wrapped in a Xamarin.Forms Layout. In that case, those (attached) BindableProperties will be transferred to the wrapper, allowing this kind of code to be valid.

var btn = new UIKit.Button();
btn.SetValue(Grid.RowProperty, 2); 

var grid = new Xamarin.Forms.Grid ();
grid.Children.Add(btn.ToView());

The SetBindingContext is not meant to be invoked directly, but it's used by the platform.

The value of this will make more sense when the Xaml support is added.

Bugs Fixed

None

API Changes

Added:
iOS:

  • public static void SetBinding(this UIView view, string propertyName, BindingBase binding, string updateSourceEventName = null);
  • public static void SetBinding(this UIView self, BindableProperty targetProperty, BindingBase binding);
  • public static void SetValue(this UIView target, BindableProperty targetProperty, object value);
  • public static void SetBindingContext(this UIView target, object bindingContext, Func<UIView, IEnumerable<UIView>> getChildren = null);

Android

  • public static void SetBinding(this global::Android.Views.View view, string propertyName, BindingBase binding, string updateSourceEventName = null);
  • public static void SetBinding(this global::Android.Views.View view, BindableProperty targetProperty, BindingBase binding);
  • public static void SetValue(this global::Android.Views.View target, BindableProperty targetProperty, object value);
  • public static void SetBindingContext(this global::Android.Views.View target, object bindingContext, Func<global::Android.Views.View, IEnumerable<global::Android.Views.View>> getChildren = null);

[U]WP

  • public static void SetBinding(this FrameworkElement view, string propertyName, BindingBase binding, string updateSourceEventName = null);
  • public static void SetBinding(this FrameworkElement view, BindableProperty targetProperty, BindingBase binding);
  • public static void SetValue(this FrameworkElement target, BindableProperty targetProperty, object value);
  • public static void SetBindingContext(this FrameworkElement target, object bindingContext, Func<FrameworkElement, IEnumerable<FrameworkElement>> getChildren = null);

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

@StephaneDelcroix StephaneDelcroix changed the title Sdx native bindings2 Native Bindings Aug 4, 2016
TargetReference = new WeakReference<TNativeView>(target);
}

public void TransferAttachedPropertiesTo(View wrapper)
Copy link
Copy Markdown
Member Author

@StephaneDelcroix StephaneDelcroix Aug 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be replaced by a static call on the helper
When that's done, the BindableProxy should be deeply hidden as a nested class

FIXED

@StephaneDelcroix StephaneDelcroix force-pushed the sdx-nativeBindings2 branch 2 times, most recently from 436535a to b6c9dfa Compare August 12, 2016 12:27
Droid.Graphics.Point currentPoint;
ColorPointer colorPointer;
ImageView imageViewSelectedColor;
ImageView imageViewPallete;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Palette

@samhouts
Copy link
Copy Markdown
Contributor

need to update docs

@rmarinho rmarinho force-pushed the sdx-nativeBindings2 branch from b6c9dfa to 6de2bd7 Compare August 16, 2016 19:03
@rmarinho
Copy link
Copy Markdown
Member

@jassmith done please review

@StephaneDelcroix
Copy link
Copy Markdown
Member Author

rebased as of today

@StephaneDelcroix StephaneDelcroix force-pushed the sdx-nativeBindings2 branch 2 times, most recently from 214e13e to 36e2470 Compare August 30, 2016 13:26
namespace Xamarin.Forms.ControlGallery.Android
{
public class ColorPickerView : ViewGroup
//, INotifyPropertyChanged
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is removing INotifyPropertyChanged intended?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just for testing


namespace Xamarin.Forms
{
static class NativeBindingHelpers
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meaty part to review. It's actually the only important part to review as well.

@jassmith jassmith merged commit 85426c5 into master Sep 8, 2016
rmarinho pushed a commit that referenced this pull request Sep 13, 2016
* [C, I, A, W] Support Native Bindings

* fix tabs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants