public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            if (!extraDetails.TryGet("framework", out ProjectFramework framework) ||
                (framework != ProjectFramework.Uwp && framework != ProjectFramework.Wpf))
            {
                return(AnalysisActions.None);
            }

            var result = AnalysisActions.EmptyList;

            if (framework.Equals(ProjectFramework.Uwp))
            {
                // TODO: Issue#163 - check for hard-coded string for  Attributes.Content
                // Then remove CheckBoxProcessor, CheckBoxCheckedAndUncheckedEventsTag & MissingCheckBoxEvents
            }

            // If using one event, the recommendation is to use both
            var hasCheckedEvent   = element.HasAttribute(Attributes.CheckedEvent);
            var hasuncheckedEvent = element.HasAttribute(Attributes.UncheckedEvent);

            if (hasCheckedEvent && !hasuncheckedEvent)
            {
                var existingCheckedName = element.Attributes.FirstOrDefault(a => a.Name == Attributes.CheckedEvent).StringValue;

                var newEventName = existingCheckedName.ToLowerInvariant().Contains("checked")
                    ? existingCheckedName.Replace("Checked", "UnChecked").Replace("checked", "Unchecked")
                    : "OnCheckBoxUnchecked";

                result.AddAttribute(
                    RapidXamlErrorType.Warning,
                    "RXT401",
                    StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsDescription,
                    StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsToolTip,
                    Attributes.UncheckedEvent,
                    newEventName,
                    StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsExtendedMessage,
                    "https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/checkbox#handle-click-and-checked-events");
            }

            if (!hasCheckedEvent && hasuncheckedEvent)
            {
                var existingUnheckedName = element.Attributes.FirstOrDefault(a => a.Name == Attributes.UncheckedEvent).StringValue;

                var newEventName = existingUnheckedName.ToLowerInvariant().Contains("unchecked")
                    ? existingUnheckedName.Replace("UnChecked", "Checked").Replace("unchecked", "checked")
                    : "OnCheckBoxChecked";

                result.AddAttribute(
                    RapidXamlErrorType.Warning,
                    "RXT401",
                    StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsDescription,
                    StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsToolTip,
                    Attributes.UncheckedEvent,
                    newEventName,
                    StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsExtendedMessage,
                    "https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/checkbox#handle-click-and-checked-events");
            }

            return(result);
        }
Esempio n. 2
0
        public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            if (!extraDetails.TryGet("framework", out ProjectFramework framework) ||
                framework != ProjectFramework.Uwp)
            {
                return(AnalysisActions.None);
            }

            var result = AnalysisActions.EmptyList;

            foreach (var attribute in element.Attributes)
            {
                if (attribute.HasStringValue)
                {
                    var attrValue = attribute.StringValue;

                    if (attrValue.StartsWith("{Binding"))
                    {
                        result.RemoveAttribute(RapidXamlErrorType.Suggestion, "RXTPOC", $"Use 'x:Bind' rather than 'Binding' for '{attribute.Name}'.", "Change to 'x:Bind'", attribute)
                        .AndAddAttribute(attribute.Name, attrValue.Replace("{Binding", "{x:Bind"));
                    }
                }
            }

            return(result);
        }
            public AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
            {
                if (extraDetails.TryGet("xmlns", out Dictionary <string, string> xmlns))
                {
                    this.Count = xmlns.Count();
                    this.Xmlns = xmlns;
                }
                else
                {
                    this.Count = 0;
                }

                return(AnalysisActions.EmptyList);
            }
Esempio n. 4
0
        public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            if (!extraDetails.TryGet("framework", out ProjectFramework framework) ||
                framework != ProjectFramework.XamarinForms)
            {
                return(AnalysisActions.None);
            }

            return(AnalysisActions.HighlightWithoutAction(
                       errorType: RapidXamlErrorType.Suggestion,
                       code: "RXT330",
                       description: "CollectionView is a more flexible, and performant alternative to ListView. Consider changing it.",
                       moreInfoUrl: "https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/",
                       descendant: element));
        }
        public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            var defaultAlias = "newns";
            var nsvalue      = "using:mynewnamespace";

            var aliasToUse = defaultAlias;

            extraDetails.TryGet("xmlns", out Dictionary <string, string> xmlns);

            if (xmlns != null)
            {
                if (xmlns.ContainsKey(defaultAlias))
                {
                    if (xmlns[defaultAlias] == nsvalue)
                    {
                        // What would be added is already there
                        return(AnalysisActions.EmptyList);
                    }
                    else
                    {
                        if (xmlns.ContainsValue(nsvalue))
                        {
                            // It already exists with a different alias
                            // In other scenarios, this might affect what is used in other operations
                        }

                        var suffix = 1;
                        while (xmlns.ContainsKey(aliasToUse))
                        {
                            aliasToUse = defaultAlias + suffix++.ToString();
                        }
                    }
                }
            }

            return(AnalysisActions.AddXmlns(
                       RapidXamlErrorType.Warning,
                       "addns",
                       $"add xmlns ({aliasToUse})",
                       "add xmlns",
                       aliasToUse,
                       nsvalue));
        }
        public AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            var defaultAllias = "controls";
            var xmlnamespace  = "using:Microsoft.UI.Xaml.Controls";
            var aliasToUse    = defaultAllias;
            var addAlias      = true;

            extraDetails.TryGet("xmlns", out Dictionary <string, string> xmlns);

            // Check to see if there is already an alias for the desired namespace
            var xns = xmlns.FirstOrDefault(x => x.Value == xmlnamespace);

            if (xns.Equals(default(KeyValuePair <string, string>)))
            {
                // Make the default alias unique (if already in use) by adding a number to the end
                var numericSuffix = 1;
                while (xmlns.ContainsKey(aliasToUse))
                {
                    aliasToUse = defaultAllias + numericSuffix++.ToString();
                }
            }
            else
            {
                aliasToUse = xns.Key;
                addAlias   = false;
            }

            // var result = AutoFixAnalysisActions.RenameElement($"{aliasToUse}:WebView2");
            var result = AnalysisActions.RenameElement(
                RapidXamlErrorType.Warning,
                "WEBV2",
                "Replace WebView with, the new and improved, WebView2",
                "Replace WebView with WebView2",
                $"{aliasToUse}:WebView2");

            if (addAlias)
            {
                result.AndAddXmlns(aliasToUse, xmlnamespace);
            }

            return(result);
        }
Esempio n. 7
0
        public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            if (!extraDetails.TryGet("framework", out ProjectFramework framework) ||
                framework != ProjectFramework.Uwp)
            {
                return(AnalysisActions.None);
            }

            var result = AnalysisActions.EmptyList;

            var ignorable = element.Attributes.FirstOrDefault(a => a.Name == "mc:Ignorable");

            this.CheckForXmlns("xamarin", element, ignorable, ref result);
            this.CheckForXmlns("not_win", element, ignorable, ref result);
            this.CheckForXmlns("android", element, ignorable, ref result);
            this.CheckForXmlns("ios", element, ignorable, ref result);
            this.CheckForXmlns("wasm", element, ignorable, ref result);
            this.CheckForXmlns("macos", element, ignorable, ref result);

            return(result);
        }
Esempio n. 8
0
        public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails)
        {
            if (!extraDetails.TryGet("framework", out ProjectFramework framework) ||
                framework != ProjectFramework.XamarinForms)
            {
                return(AnalysisActions.None);
            }

            // Don't report anything if the source hasn't been set.
            // Allow for multiple possible values that could be used by accesibility tools.
            if (element.HasAttribute(Attributes.Source) &&
                !element.HasAttribute(Attributes.AutomationId) &&
                !element.HasAttribute(Attributes.APName) &&
                !element.HasAttribute(Attributes.APHelpText) &&
                !element.HasAttribute(Attributes.APLabeledBy))
            {
                if (!element.TryGetAttributeStringValue(Attributes.APIsInAccessibleTree, out string inTree) ||
                    inTree.Equals("true", System.StringComparison.InvariantCultureIgnoreCase))
                {
                    return(AnalysisActions.AddAttribute(
                               RapidXamlErrorType.Warning,
                               code: "RXT350",
                               description: StringRes.UI_XamlAnalysisImageAccessibilityDescription,
                               actionText: StringRes.UI_UndoContextAddAutomationDescription,
                               addAttributeName: Attributes.APName,
                               addAttributeValue: "Set this to something meaningful",
                               moreInfoUrl: null,
                               extendedMessage: StringRes.UI_XamlAnalysisImageAccessibilityExtendedMessage)
                           .OrAddAttribute(
                               actionText: StringRes.UI_UndoContextExcludeFromAutomation,
                               addAttributeName: Attributes.APIsInAccessibleTree,
                               addAttributeValue: "false"));
                }
            }

            return(AnalysisActions.None);
        }