summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/ColorExtensions.cs5
-rw-r--r--Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs33
-rw-r--r--Xamarin.Forms.Platform.Android/NativeViewWrapper.cs10
-rw-r--r--Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj6
4 files changed, 53 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.Android/ColorExtensions.cs b/Xamarin.Forms.Platform.Android/ColorExtensions.cs
index db190b4a..93e23124 100644
--- a/Xamarin.Forms.Platform.Android/ColorExtensions.cs
+++ b/Xamarin.Forms.Platform.Android/ColorExtensions.cs
@@ -36,5 +36,10 @@ namespace Xamarin.Forms.Platform.Android
int disabled = defaults.GetColorForState(States[1], color.ToAndroid());
return new ColorStateList(States, new[] { color.ToAndroid().ToArgb(), disabled });
}
+
+ public static Color ToColor(this AColor color)
+ {
+ return Color.FromUint((uint)color.ToArgb());
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs
new file mode 100644
index 00000000..fd072461
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ public static class NativeBindingExtensions
+ {
+ public static void SetBinding(this global::Android.Views.View view, string propertyName, BindingBase binding, string updateSourceEventName = null)
+ {
+ NativeBindingHelpers.SetBinding(view, propertyName, binding, updateSourceEventName);
+ }
+
+ public static void SetBinding(this global::Android.Views.View view, BindableProperty targetProperty, BindingBase binding)
+ {
+ NativeBindingHelpers.SetBinding(view, targetProperty, binding);
+ }
+
+ public static void SetValue(this global::Android.Views.View target, BindableProperty targetProperty, object value)
+ {
+ NativeBindingHelpers.SetValue(target, targetProperty, 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)
+ {
+ NativeBindingHelpers.SetBindingContext(target, bindingContext, getChildren);
+ }
+
+ internal static void TransferBindablePropertiesToWrapper(this global::Android.Views.View target, View wrapper)
+ {
+ NativeBindingHelpers.TransferBindablePropertiesToWrapper(target, wrapper);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs b/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs
index eecef9bc..53b5253c 100644
--- a/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs
+++ b/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs
@@ -1,3 +1,5 @@
+using Android.Views;
+
namespace Xamarin.Forms.Platform.Android
{
public class NativeViewWrapper : View
@@ -9,6 +11,8 @@ namespace Xamarin.Forms.Platform.Android
NativeView = nativeView;
OnLayoutDelegate = onLayoutDelegate;
OnMeasureDelegate = onMeasureDelegate;
+
+ nativeView.TransferBindablePropertiesToWrapper(this);
}
public GetDesiredSizeDelegate GetDesiredSizeDelegate { get; }
@@ -18,5 +22,11 @@ namespace Xamarin.Forms.Platform.Android
public OnLayoutDelegate OnLayoutDelegate { get; }
public OnMeasureDelegate OnMeasureDelegate { get; }
+
+ protected override void OnBindingContextChanged()
+ {
+ NativeView.SetBindingContext(BindingContext, (view) => (view as ViewGroup)?.GetChildrenOfType<global::Android.Views.View>());
+ base.OnBindingContextChanged();
+ }
}
} \ 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 33bfa03f..00179717 100644
--- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
+++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
@@ -241,6 +241,7 @@
<Compile Include="AppCompat\FormsFragmentPagerAdapter.cs" />
<Compile Include="AndroidAppIndexProvider.cs" />
<Compile Include="Renderers\FormsSeekBar.cs" />
+ <Compile Include="Extensions\NativeBindingExtensions.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.
@@ -263,6 +264,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="Extensions\" />
+ </ItemGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets" Condition="Exists('..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
@@ -271,4 +275,4 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets'))" />
</Target>
-</Project> \ No newline at end of file
+</Project>