summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.Android/Activity1.cs
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-08 20:39:05 +0200
committerJason Smith <jason.smith@xamarin.com>2016-09-08 11:39:05 -0700
commit85426c5d9495eb1d55b3128bf97e50c68a73b53f (patch)
tree2f81e5868ce61eb90d15c6c51a354603b8395627 /Xamarin.Forms.ControlGallery.Android/Activity1.cs
parent11326e1c182b3ff5c3d82c6ef7d09c193bc19891 (diff)
downloadxamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.gz
xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.bz2
xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.zip
Native Bindings (#278)
* [C, I, A, W] Support Native Bindings * fix tabs
Diffstat (limited to 'Xamarin.Forms.ControlGallery.Android/Activity1.cs')
-rw-r--r--Xamarin.Forms.ControlGallery.Android/Activity1.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/Activity1.cs b/Xamarin.Forms.ControlGallery.Android/Activity1.cs
index bc1772c6..35f877dc 100644
--- a/Xamarin.Forms.ControlGallery.Android/Activity1.cs
+++ b/Xamarin.Forms.ControlGallery.Android/Activity1.cs
@@ -20,6 +20,7 @@ using System.IO;
using System.IO.IsolatedStorage;
using Droid = Android;
+using System.Globalization;
[assembly: Dependency (typeof (CacheService))]
@@ -337,6 +338,14 @@ namespace Xamarin.Forms.ControlGallery.Android
if (nncgPage != null) {
AddNativeControls (nncgPage);
}
+
+ var nncgPage1 = args.Page as NativeBindingGalleryPage;
+
+ if (nncgPage1 != null)
+ {
+ AddNativeBindings(nncgPage1);
+ }
+
};
}
@@ -408,6 +417,58 @@ namespace Xamarin.Forms.ControlGallery.Android
var size = new Size (nativeView.MeasuredWidth, nativeView.MeasuredHeight);
return new SizeRequest (size);
}
+
+ void AddNativeBindings(NativeBindingGalleryPage page)
+ {
+ if (page.NativeControlsAdded)
+ return;
+
+ StackLayout sl = page.Layout;
+
+ var textView = new TextView(this)
+ {
+ TextSize = 14,
+ Text = "This will be text"
+ };
+
+ var viewGroup = new LinearLayout(this);
+ viewGroup.AddView(textView);
+
+ var buttonColor = new global::Android.Widget.Button(this) { Text = "Change label Color" };
+ buttonColor.Click += (sender, e) => textView.SetTextColor(Color.Blue.ToAndroid());
+
+ var colorPicker = new ColorPickerView(this, 200, 200);
+
+ textView.SetBinding(nameof(textView.Text), new Binding("NativeLabel"));
+ //this doesn't work because there's not TextColor property
+ //textView.SetBinding("TextColor", new Binding("NativeLabelColor", converter: new ColorConverter()));
+ colorPicker.SetBinding(nameof(colorPicker.SelectedColor), new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorConverter()), "ColorPicked");
+
+ sl?.Children.Add(viewGroup);
+ sl?.Children.Add(buttonColor.ToView());
+ sl?.Children.Add(colorPicker);
+
+ page.NativeControlsAdded = true;
+ }
+
+ public class ColorConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is Color)
+ return ((Color)value).ToAndroid();
+
+ return null;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is global::Android.Graphics.Color)
+ return ((global::Android.Graphics.Color)value).ToColor();
+
+ return null;
+ }
+ }
}
#endif
}