コード例 #1
0
        public static void UnResolveSubject(IInteractivitySubject interactivitySubject)
        {
            if (IsResolved(interactivitySubject) == false)
            {
                return;
            }

            if (IsSpecified(interactivitySubject) == false)
            {
                interactivitySubject.SubjectStore = null;

                return;
            }

            interactivitySubject.SubjectKind &= SubjectKind.Unspecified;
            switch (interactivitySubject.SubjectKind)
            {
            case SubjectKind.Explicit:
                if (interactivitySubject.SubjectStore is BindingProxyBase bindingProxy)
                {
                    interactivitySubject.SubjectStore = bindingProxy.Binding;
                    bindingProxy.Dispose();
                }
                break;

            case SubjectKind.Name:
                interactivitySubject.SubjectStore = GetSubjectName(interactivitySubject);
                break;
            }
        }
コード例 #2
0
        private static DependencyObject UnwrapResolved(IInteractivitySubject interactivitySubject)
        {
            if (interactivitySubject.SubjectStore is BindingProxyBase bindingProxyBase)
            {
                return(bindingProxyBase.Value as DependencyObject);
            }

            return((DependencyObject)interactivitySubject.SubjectStore);
        }
コード例 #3
0
        public static void SetSubjectName(IInteractivitySubject interactivitySubject, string value)
        {
            if (ReferenceEquals(interactivitySubject.SubjectStore, value))
            {
                return;
            }

            UnResolveSubject(interactivitySubject);

            interactivitySubject.SubjectStore = value;
            interactivitySubject.SubjectKind  = SubjectKind.Name;
        }
コード例 #4
0
        public static void SetExplicitSubject(IInteractivitySubject interactivitySubject, object value)
        {
            if (ReferenceEquals(interactivitySubject.SubjectStore, value))
            {
                return;
            }

            UnResolveSubject(interactivitySubject);

            interactivitySubject.SubjectStore = value;
            interactivitySubject.SubjectKind  = SubjectKind.Explicit;
        }
コード例 #5
0
        public static string GetSubjectName(IInteractivitySubject interactivitySubject)
        {
            var subjectKind = interactivitySubject.SubjectKind;

            subjectKind &= SubjectKind.Unspecified;

            if (subjectKind == SubjectKind.Unspecified || subjectKind != SubjectKind.Name)
            {
                return(null);
            }

            // Unwrap if resolved through Binding
            return((interactivitySubject.SubjectStore as BindingProxyBase)?.Binding.ElementName ?? (string)interactivitySubject.SubjectStore);
        }
コード例 #6
0
        public static object GetExplicitSubject(IInteractivitySubject interactivitySubject)
        {
            var subjectKind = interactivitySubject.SubjectKind;

            subjectKind &= SubjectKind.Unspecified;

            if (subjectKind == SubjectKind.Unspecified || subjectKind != SubjectKind.Explicit)
            {
                return(null);
            }

            // Unwrap if resolved through Binding
            return((interactivitySubject.SubjectStore as BindingProxyBase)?.Binding ?? interactivitySubject.SubjectStore);
        }
コード例 #7
0
        private static DependencyObject InstallBinding(IInteractivitySubject interactivitySubject, NativeBinding binding)
        {
            var interactivityTarget = interactivitySubject.GetInteractivityObject().InteractivityTarget;

            if (interactivityTarget == null)
            {
                return(null);
            }

            var subjectBindingProxy = new SubjectBindingProxy(binding, interactivitySubject);

            interactivitySubject.SubjectStore = subjectBindingProxy;
            interactivitySubject.SubjectKind |= SubjectKind.Resolved;

            return(subjectBindingProxy.Value as DependencyObject);
        }
コード例 #8
0
        public static void CopyFrom(IInteractivitySubject target, IInteractivitySubject source)
        {
            var sourceSubjectKind = source.SubjectKind & SubjectKind.Unspecified;

            if (sourceSubjectKind == 0)
            {
                sourceSubjectKind = SubjectKind.Unspecified;
            }

            switch (sourceSubjectKind)
            {
            case SubjectKind.Name:
                SetSubjectName(target, GetSubjectName(source));
                break;

            case SubjectKind.Explicit:
                SetExplicitSubject(target, GetExplicitSubject(source));
                break;
            }
        }
コード例 #9
0
        public static DependencyObject ResolveSubject(IInteractivitySubject interactivitySubject)
        {
            if (IsResolved(interactivitySubject))
            {
                return(UnwrapResolved(interactivitySubject));
            }

            var interactivityObject = interactivitySubject.GetInteractivityObject();

            if (interactivityObject.IsLoaded == false)
            {
                return(null);
            }

            var interactivityRoot = interactivityObject.Root;

            // TODO Setters should apply values on Interactivity root only, however Triggers could interact with other controls on Page. Need to check setters behavior in future.
            if (interactivityRoot is StyleRoot && interactivityObject is SetterBase)
            {
                return(interactivityRoot.InteractivityTarget);
            }

            var subjectKind = interactivitySubject.SubjectKind;

            subjectKind &= SubjectKind.Unspecified;

            var interactivityTarget = interactivityObject.InteractivityTarget;
            var subject             = interactivitySubject.SubjectStore;

            // Explicit
            if (subjectKind == SubjectKind.Explicit)
            {
                var binding = subject as NativeBinding;

                if (subject is BindingBaseExtension bindingBase)
                {
                    binding = bindingBase.GetBinding(interactivityTarget, null);
                }

                if (binding != null)
                {
                    return(InstallBinding(interactivitySubject, binding));
                }

                interactivitySubject.SubjectKind |= SubjectKind.Resolved;

                return(subject as DependencyObject);
            }
            // Name
            if (subjectKind == SubjectKind.Name)
            {
                return(InstallBinding(interactivitySubject, new NativeBinding {
                    ElementName = (string)subject, BindsDirectlyToSource = true
                }));
            }

            // InteractivityTarget
            if (interactivityTarget == null)
            {
                return(null);
            }

            interactivitySubject.SubjectStore = interactivityTarget;
            interactivitySubject.SubjectKind  = SubjectKind.Resolved;

            return(interactivityTarget);
        }
コード例 #10
0
 public static bool IsSpecified(IInteractivitySubject interactivitySubject)
 {
     return((interactivitySubject.SubjectKind & SubjectKind.Unspecified) != SubjectKind.Unspecified);
 }
コード例 #11
0
 public static bool IsResolved(IInteractivitySubject interactivitySubject)
 {
     return((interactivitySubject.SubjectKind & SubjectKind.Resolved) != 0);
 }
コード例 #12
0
 public static InteractivityObject GetInteractivityObject(this IInteractivitySubject interactivitySubject)
 {
     return((InteractivityObject)interactivitySubject);
 }
コード例 #13
0
 public SubjectBindingProxy(NativeBinding binding, IInteractivitySubject interactivitySubject) : base(binding, interactivitySubject.GetInteractivityObject().InteractivityTarget)
 {
     _interactivityObject = interactivitySubject;
 }