diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-09-08 20:45:43 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-09-08 11:45:43 -0700 |
commit | 3b7d798fdda51a669683ed7d5c3770ebf3adfa77 (patch) | |
tree | 8e4d16d91e9a6cb5a49a8aecf8514a8c84f36b97 /Xamarin.Forms.Platform.iOS | |
parent | 85426c5d9495eb1d55b3128bf97e50c68a73b53f (diff) | |
download | xamarin-forms-3b7d798fdda51a669683ed7d5c3770ebf3adfa77.tar.gz xamarin-forms-3b7d798fdda51a669683ed7d5c3770ebf3adfa77.tar.bz2 xamarin-forms-3b7d798fdda51a669683ed7d5c3770ebf3adfa77.zip |
[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.iOS')
3 files changed, 62 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.iOS/NativeBindingService.cs b/Xamarin.Forms.Platform.iOS/NativeBindingService.cs new file mode 100644 index 00000000..3756e2f0 --- /dev/null +++ b/Xamarin.Forms.Platform.iOS/NativeBindingService.cs @@ -0,0 +1,39 @@ +using System; +using UIKit; + +[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.iOS.NativeBindingService))] + +namespace Xamarin.Forms.Platform.iOS +{ + class NativeBindingService : Xaml.INativeBindingService + { + public bool TrySetBinding(object target, string propertyName, BindingBase binding) + { + var view = target as UIView; + 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 UIView; + if (view == null) + return false; + view.SetBinding(property, binding); + return true; + } + + public bool TrySetValue(object target, BindableProperty property, object value) + { + var view = target as UIView; + if (view == null) + return false; + view.SetValue(property, value); + return true; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs b/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs new file mode 100644 index 00000000..9e20e045 --- /dev/null +++ b/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs @@ -0,0 +1,20 @@ +using System; +using UIKit; + +[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.iOS.NativeValueConverterService))] + +namespace Xamarin.Forms.Platform.iOS +{ + class NativeValueConverterService : Xaml.INativeValueConverterService + { + public bool ConvertTo(object value, Type toType, out object nativeValue) + { + nativeValue = null; + if (typeof(UIView).IsInstanceOfType(value) && toType.IsAssignableFrom(typeof(View))) { + nativeValue = ((UIView)value).ToView(); + return true; + } + return false; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj index 8fde4c81..e31aa3ac 100644 --- a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj +++ b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj @@ -150,6 +150,8 @@ <Compile Include="IOSAppLinks.cs" /> <Compile Include="NativeViewPropertyListener.cs" /> <Compile Include="Extensions\LayoutExtensions.cs" /> + <Compile Include="NativeValueConverterService.cs" /> + <Compile Include="NativeBindingService.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="Resources\StringResources.ar.resx" /> @@ -205,4 +207,4 @@ <Link>Properties\GlobalAssemblyInfo.cs</Link> </Compile> </ItemGroup> -</Project>
\ No newline at end of file +</Project> |