Esempio n. 1
0
        Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo)
        {
            var parents = parentValueProvider.ParentObjects.ToList();

            // Skip 0; we would not be making this check if TargetObject were not a Setter
            // Skip 1; we would not be making this check if the immediate parent were not a VisualState

            // VisualStates must be in a VisualStateGroup
            if (!(parents[2] is VisualStateGroup))
            {
                throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo);
            }

            var vsTarget = parents[3];

            // Are these Visual States directly on a VisualElement?
            if (vsTarget is /*VisualElement*/ BaseHandle)
            {
                return(vsTarget.GetType());
            }

            if (!(parents[3] is VisualStateGroupList))
            {
                throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo);
            }

            if (!(parents[4] is Setter))
            {
                throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
            }

            throw new XamlParseException("NUI doesn't support VisualState", lineInfo);
        }
Esempio n. 2
0
        Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo)
        {
            var parents = parentValueProvider.ParentObjects.ToList();

            // Skip 0; we would not be making this check if TargetObject were not a Setter
            // Skip 1; we would not be making this check if the immediate parent were not a VisualState

            // VisualStates must be in a VisualStateGroup
            if (parents[2] is not VisualStateGroup)
            {
                throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo);
            }

            // Are these Visual States directly on a VisualElement?
            if (parents[3] is VisualElement vsTarget)
            {
                return(vsTarget.GetType());
            }

            if (parents[3] is not VisualStateGroupList)
            {
                throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo);
            }

            if (parents[4] is VisualElement veTarget)
            {
                return(veTarget.GetType());
            }

            if (parents[4] is not Setter)
            {
                throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
            }

            if (parents[5] is TriggerBase trigger)
            {
                return(trigger.TargetType);
            }

            // These must be part of a Style; verify that
            if (parents[5] is Style style)
            {
                return(style.TargetType);
            }

            throw new XamlParseException($"Unable to find a TragetType for the Bindable Property. Try prefixing it with the TargetType.", lineInfo);
        }
        Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo)
        {
            var parents = parentValueProvider.ParentObjects.ToList();

            // Skip 0; we would not be making this check if TargetObject were not a Setter
            // Skip 1; we would not be making this check if the immediate parent were not a VisualState

            // VisualStates must be in a VisualStateGroup
            if (!(parents[2] is VisualStateGroup))
            {
                throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo);
            }

            var vsTarget = parents[3];

            // Are these Visual States directly on a VisualElement?
            if (vsTarget is VisualElement)
            {
                return(vsTarget.GetType());
            }

            if (!(parents[3] is VisualStateGroupList))
            {
                throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo);
            }

            if (!(parents[4] is Setter))
            {
                throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
            }

            // These must be part of a Style; verify that
            if (!(parents[5] is Style style))
            {
                throw new XamlParseException($"Expected {nameof(Style)} but found {parents[5]}.", lineInfo);
            }

            return(style.TargetType);
        }