diff options
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs index 9847867c..eab88e81 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs @@ -1,13 +1,9 @@ +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; -using System; -#if __UNIFIED__ using UIKit; - -#else -using MonoTouch.UIKit; -#endif +using static System.String; namespace Xamarin.Forms.Platform.iOS { @@ -28,6 +24,47 @@ namespace Xamarin.Forms.Platform.iOS return new SizeRequest(request, minimum); } + public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase, string updateSourceEventName = null) + { + var binding = bindingBase as Binding; + //This will allow setting bindings from Xaml by reusing the MarkupExtension + updateSourceEventName = updateSourceEventName ?? binding?.UpdateSourceEventName; + + if (!IsNullOrEmpty(updateSourceEventName)) + { + NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, updateSourceEventName); + return; + } + + NativeViewPropertyListener nativePropertyListener = null; + if (bindingBase.Mode == BindingMode.TwoWay) { + nativePropertyListener = new NativeViewPropertyListener(propertyName); + view.AddObserver(nativePropertyListener, propertyName, 0, IntPtr.Zero); + } + + NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener); + } + + public static void SetBinding(this UIView self, BindableProperty targetProperty, BindingBase binding) + { + NativeBindingHelpers.SetBinding(self, targetProperty, binding); + } + + public static void SetValue(this UIView target, BindableProperty targetProperty, object value) + { + NativeBindingHelpers.SetValue(target, targetProperty, value); + } + + public static void SetBindingContext(this UIView target, object bindingContext, Func<UIView, IEnumerable<UIView>> getChildren = null) + { + NativeBindingHelpers.SetBindingContext(target, bindingContext, getChildren); + } + + internal static void TransferbindablePropertiesToWrapper(this UIView target, View wrapper) + { + NativeBindingHelpers.TransferBindablePropertiesToWrapper(target, wrapper); + } + internal static T FindDescendantView<T>(this UIView view) where T : UIView { var queue = new Queue<UIView>(); |