Exemple #1
0
        internal override async void Apply(object newContext, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
        {
            var view = bindObj as Element;

            if (view == null)
            {
                throw new InvalidOperationException();
            }

            base.Apply(newContext, bindObj, targetProperty, fromBindingContextChanged);

            Element templatedParent = await TemplateUtilities.FindTemplatedParentAsync(view);

            ApplyInner(templatedParent, bindObj, targetProperty);
        }
Exemple #2
0
		static async void OnContentChanged(BindableObject bindable, object oldValue, object newValue)
		{
			var self = (ContentPresenter)bindable;

			var oldView = (View)oldValue;
			var newView = (View)newValue;
			if (oldView != null)
			{
				self.InternalChildren.Remove(oldView);
				oldView.ParentOverride = null;
			}

			if (newView != null)
			{
				self.InternalChildren.Add(newView);
				newView.ParentOverride = await TemplateUtilities.FindTemplatedParentAsync((Element)bindable);
			}
		}
Exemple #3
0
#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
        async void ApplyRelativeSourceBinding(
            BindableObject targetObject,
            BindableProperty targetProperty)
#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void
        {
            if (!(Source is RelativeBindingSource relativeSource))
            {
                return;
            }

            var relativeSourceTarget = RelativeSourceTargetOverride ?? targetObject as Element;

            if (!(relativeSourceTarget is Element))
            {
                throw new InvalidOperationException();
            }

            object resolvedSource = null;

            switch (relativeSource.Mode)
            {
            case RelativeBindingSourceMode.Self:
                resolvedSource = relativeSourceTarget;
                break;

            case RelativeBindingSourceMode.TemplatedParent:
                resolvedSource = await TemplateUtilities.FindTemplatedParentAsync(relativeSourceTarget);

                break;

            case RelativeBindingSourceMode.FindAncestor:
            case RelativeBindingSourceMode.FindAncestorBindingContext:
                ApplyAncestorTypeBinding(targetObject, relativeSourceTarget, targetProperty);
                return;

            default:
                throw new InvalidOperationException();
            }

            _expression.Apply(resolvedSource, targetObject, targetProperty);
        }