コード例 #1
0
        protected override void Update(global::Android.Views.View view, SemanticEffectRouter effect)
        {
            var isHeading = SemanticEffect.GetHeadingLevel(Element) != CommunityToolkit.Effects.Semantic.HeadingLevel.None;

            ViewCompat.SetAccessibilityHeading(view, isHeading);

            var a11yVisibility = SemanticEffect.GetSemanticInclusion(Element);

            switch (a11yVisibility)
            {
            case SemanticInclusion.Default:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityAuto);
                break;

            case SemanticInclusion.Include:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityYes);
                break;

            case SemanticInclusion.Exclude:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityNo);
                break;

            case SemanticInclusion.ExcludeWithChildren:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityNoHideDescendants);
                break;
            }

            var desc = SemanticEffect.GetDescription(Element);
            var hint = SemanticEffect.GetHint(Element);

            if (!string.IsNullOrWhiteSpace(hint) || !string.IsNullOrWhiteSpace(desc))
            {
                if (semanticAccessibilityDelegate == null)
                {
                    semanticAccessibilityDelegate = new SemanticAccessibilityDelegate(Element);
                    ViewCompat.SetAccessibilityDelegate(view, semanticAccessibilityDelegate);
                }
            }
            else if (semanticAccessibilityDelegate != null)
            {
                semanticAccessibilityDelegate = null;
                ViewCompat.SetAccessibilityDelegate(view, null);
            }

            if (semanticAccessibilityDelegate != null)
            {
                semanticAccessibilityDelegate.Element = Element;
                view.ImportantForAccessibility        = global::Android.Views.ImportantForAccessibility.Yes;
            }
        }