示例#1
0
        private static void OnBindPropertyChanged(object bindable, object oldValue, object newValue)
        {
            var bindings = (string)newValue;

            if (string.IsNullOrWhiteSpace(bindings))
            {
                return;
            }
            var nativeView = GetNativeViewHandler?.Invoke((BindableObject)bindable);

            if (nativeView != null)
            {
                nativeView.SetBindingMemberValue(AttachedMembersBase.Object.Parent, bindable);
                bindable = nativeView;
            }
            if (XamarinFormsToolkitExtensions.IsDesignMode)
            {
                XamarinFormsDataBindingExtensions.InitializeFromDesignContext();
                var list = BindingServiceProvider.BindingProvider.CreateBindingsFromStringWithBindings(bindable, bindings);
                foreach (var binding in list.OfType <InvalidDataBinding>())
                {
                    throw binding.Exception;
                }
            }
            else
            {
                BindingServiceProvider.BindingProvider.CreateBindingsFromString(bindable, bindings);
            }
        }
示例#2
0
        private static void OnHasNativeViewChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var element = bindable as Element;

            if (!(newValue is bool) || element == null)
            {
                return;
            }
            if ((bool)newValue)
            {
                element.ChildAdded += OnChildAdded;
                if (GetNativeViewHandler == null)
                {
                    return;
                }

                var content = XamarinFormsDataBindingExtensions.GetContent(element);
                if (content is string)
                {
                    return;
                }

                var enumerable = content as IEnumerable;
                if (enumerable == null)
                {
                    return;
                }

                foreach (var item in enumerable.OfType <BindableObject>())
                {
                    var nativeView = GetNativeViewHandler.Invoke(item);
                    nativeView?.SetBindingMemberValue(AttachedMembersBase.Object.Parent, item);
                }
            }
            else
            {
                element.ChildAdded -= OnChildAdded;
            }
        }
示例#3
0
        private static void OnChildAdded(object sender, ElementEventArgs args)
        {
            var nativeView = GetNativeViewHandler?.Invoke(args.Element);

            nativeView?.SetBindingMemberValue(AttachedMembersBase.Object.Parent, args.Element);
        }