summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-08 18:45:43 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-09-08 18:45:43 (GMT)
commit3b7d798fdda51a669683ed7d5c3770ebf3adfa77 (patch)
tree8e4d16d91e9a6cb5a49a8aecf8514a8c84f36b97 /Xamarin.Forms.Platform.Android
parent85426c5d9495eb1d55b3128bf97e50c68a73b53f (diff)
downloadxamarin-forms-3b7d798fdda51a669683ed7d5c3770ebf3adfa77.zip
xamarin-forms-3b7d798fdda51a669683ed7d5c3770ebf3adfa77.tar.gz
xamarin-forms-3b7d798fdda51a669683ed7d5c3770ebf3adfa77.tar.bz2
[Xaml] support native views and native bindings (#266)
Allows including Native views directly in xaml. Support for ios, android, UWP
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/NativeBindingservice.cs39
-rw-r--r--Xamarin.Forms.Platform.Android/NativeValueConverterService.cs19
-rw-r--r--Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj2
3 files changed, 60 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/NativeBindingservice.cs b/Xamarin.Forms.Platform.Android/NativeBindingservice.cs
new file mode 100644
index 0000000..3dd4fe3
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/NativeBindingservice.cs
@@ -0,0 +1,39 @@
+´╗┐using System;
+using AView = Android.Views.View;
+
+[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.Android.NativeBindingService))]
+
+namespace Xamarin.Forms.Platform.Android
+{
+ class NativeBindingService : Xaml.INativeBindingService
+ {
+ public bool TrySetBinding(object target, string propertyName, BindingBase binding)
+ {
+ var view = target as AView;
+ if (view == null)
+ return false;
+ if (target.GetType().GetProperty(propertyName)?.GetMethod == null)
+ return false;
+ view.SetBinding(propertyName, binding);
+ return true;
+ }
+
+ public bool TrySetBinding(object target, BindableProperty property, BindingBase binding)
+ {
+ var view = target as AView;
+ if (view == null)
+ return false;
+ view.SetBinding(property, binding);
+ return true;
+ }
+
+ public bool TrySetValue(object target, BindableProperty property, object value)
+ {
+ var view = target as AView;
+ if (view == null)
+ return false;
+ view.SetValue(property, value);
+ return true;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/NativeValueConverterService.cs b/Xamarin.Forms.Platform.Android/NativeValueConverterService.cs
new file mode 100644
index 0000000..ff6faa9
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/NativeValueConverterService.cs
@@ -0,0 +1,19 @@
+´╗┐using System;
+using AView = Android.Views.View;
+
+[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.Android.NativeValueConverterService))]
+namespace Xamarin.Forms.Platform.Android
+{
+ class NativeValueConverterService : Xaml.INativeValueConverterService
+ {
+ public bool ConvertTo(object value, Type toType, out object nativeValue)
+ {
+ nativeValue = null;
+ if (typeof(AView).IsInstanceOfType(value) && toType.IsAssignableFrom(typeof(View))) {
+ nativeValue = ((AView)value).ToView();
+ return true;
+ }
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
index 0017971..2852b85 100644
--- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
+++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
@@ -242,6 +242,8 @@
<Compile Include="AndroidAppIndexProvider.cs" />
<Compile Include="Renderers\FormsSeekBar.cs" />
<Compile Include="Extensions\NativeBindingExtensions.cs" />
+ <Compile Include="NativeValueConverterService.cs" />
+ <Compile Include="NativeBindingservice.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.