diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-09-08 20:39:05 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-09-08 11:39:05 -0700 |
commit | 85426c5d9495eb1d55b3128bf97e50c68a73b53f (patch) | |
tree | 2f81e5868ce61eb90d15c6c51a354603b8395627 /Xamarin.Forms.Platform.WinRT/NativeBindingExtensions.cs | |
parent | 11326e1c182b3ff5c3d82c6ef7d09c193bc19891 (diff) | |
download | xamarin-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.Platform.WinRT/NativeBindingExtensions.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/NativeBindingExtensions.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/NativeBindingExtensions.cs b/Xamarin.Forms.Platform.WinRT/NativeBindingExtensions.cs new file mode 100644 index 00000000..cc88c87e --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT/NativeBindingExtensions.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Windows.UI.Xaml; +using static System.String; +#if WINDOWS_UWP + +namespace Xamarin.Forms.Platform.UWP +#else + +namespace Xamarin.Forms.Platform.WinRT +#endif +{ + public static class NativeBindingExtensions + { + public static void SetBinding(this FrameworkElement view, string propertyName, BindingBase bindingBase, string updateSourceEventName = null) + { + var binding = bindingBase as Binding; + updateSourceEventName = updateSourceEventName ?? binding?.UpdateSourceEventName; + + if (IsNullOrEmpty(updateSourceEventName)) + { + NativePropertyListener nativePropertyListener = null; + if (bindingBase.Mode == BindingMode.TwoWay) + nativePropertyListener = new NativePropertyListener(view, propertyName); + + NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener as INotifyPropertyChanged); + return; + } + + NativeEventWrapper eventE = null; + if (binding.Mode == BindingMode.TwoWay && !(view is INotifyPropertyChanged)) + eventE = new NativeEventWrapper(view, propertyName, updateSourceEventName); + + NativeBindingHelpers.SetBinding(view, propertyName, binding, eventE); + } + + public static void SetBinding(this FrameworkElement view, BindableProperty targetProperty, BindingBase binding) + { + NativeBindingHelpers.SetBinding(view, targetProperty, binding); + } + + public static void SetValue(this FrameworkElement target, BindableProperty targetProperty, object value) + { + NativeBindingHelpers.SetValue(target, targetProperty, value); + } + + public static void SetBindingContext(this FrameworkElement target, object bindingContext, Func<FrameworkElement, IEnumerable<FrameworkElement>> getChildren = null) + { + NativeBindingHelpers.SetBindingContext(target, bindingContext, getChildren); + } + + internal static void TransferbindablePropertiesToWrapper(this FrameworkElement target, View wrapper) + { + NativeBindingHelpers.TransferBindablePropertiesToWrapper(target, wrapper); + } + } +}
\ No newline at end of file |