protected void UpdateAutomationId()
 {
     if (!string.IsNullOrEmpty(Element.AutomationId))
     {
         WAutomationProperties.SetAutomationId(Control, Element.AutomationId);
     }
 }
        protected void UpdateAutomationHelpText()
        {
            var helpText = AutomationProperties.GetHelpText(Element);

            if (!string.IsNullOrEmpty(helpText))
            {
                WAutomationProperties.SetHelpText(Control, helpText);
            }
        }
        protected void UpdateAutomationLabeledBy()
        {
            var label = AutomationProperties.GetLabeledBy(Element);

            if (label != null)
            {
                WAutomationProperties.SetLabeledBy(Control, Platform.GetRenderer(label)?.GetNativeElement());
            }
        }
        protected void UpdateAutomationName()
        {
            var name = AutomationProperties.GetName(Element);

            if (!string.IsNullOrEmpty(name))
            {
                WAutomationProperties.SetName(Control, name);
            }
        }
Esempio n. 5
0
        async void UpdateContent()
        {
            var text         = Element.UpdateFormsText(Element.Text, Element.TextTransform);
            var elementImage = await Element.ImageSource.ToWindowsImageSourceAsync();

            // No image, just the text
            if (elementImage == null)
            {
                Control.Content = text;
                Element?.InvalidateMeasureNonVirtual(InvalidationTrigger.RendererReady);
                return;
            }

            var image = new WImage
            {
                Source              = elementImage,
                Width               = 30,
                Height              = 30,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            // No text, just the image
            if (string.IsNullOrEmpty(text))
            {
                Control.Content = image;
                Element?.InvalidateMeasureNonVirtual(InvalidationTrigger.RendererReady);
                return;
            }

            // Both image and text, so we need to build a container for them
            var layout    = Element.ContentLayout;
            var container = new StackPanel();
            var textBlock = new TextBlock
            {
                Text = text,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            // narrator doesn't pick up text content when nested in a layout so set automation name unless set explicitly
            if (string.IsNullOrEmpty(WAutomationProperties.GetName(Control)))
            {
                WAutomationProperties.SetName(Control, text);
            }

            var spacing = layout.Spacing;

            container.HorizontalAlignment = HorizontalAlignment.Center;
            container.VerticalAlignment   = VerticalAlignment.Center;

            switch (layout.Position)
            {
            case Button.ButtonContentLayout.ImagePosition.Top:
                container.Orientation = Orientation.Vertical;
                image.Margin          = new WThickness(0, 0, 0, spacing);
                break;

            case Button.ButtonContentLayout.ImagePosition.Bottom:
                container.Orientation = Orientation.Vertical;
                image.Margin          = new WThickness(0, spacing, 0, 0);
                break;

            case Button.ButtonContentLayout.ImagePosition.Right:
                container.Orientation = Orientation.Horizontal;
                image.Margin          = new WThickness(spacing, 0, 0, 0);
                break;

            default:
                // Defaults to image on the left
                container.Orientation = Orientation.Horizontal;
                image.Margin          = new WThickness(0, 0, spacing, 0);
                break;
            }

            container.Children.Add(image);
            container.Children.Add(textBlock);

            Control.Content = container;
            Element?.InvalidateMeasureNonVirtual(InvalidationTrigger.RendererReady);
        }