Windows narrator is not reading the custom tooltip content?

428 views Asked by At

I have a requirement to read the content of complex tooltip content for WPF or UWP application by narrator. I am facing challenge to read the content visible for tooltip. Have tried to override the AutomationPeer class and there methods. But no luck :(

My XAML UI is below:

 <Button Content="Submit" Grid.Row="2" Height="100" Width="200"  >
        <Button.ToolTip  x:Uid="Addition_Details" > 
            <local:MyStackPanel Orientation="Vertical"  Focusable="True" KeyboardNavigation.TabIndex="0" ForceCursor="True">
                <TextBlock Text="Additional Details" KeyboardNavigation.TabIndex="1"/>
                <TextBlock Text="Driver" KeyboardNavigation.TabIndex="2"/>
                <TextBlock Text="A0221" KeyboardNavigation.TabIndex="3"/>
            </local:MyStackPanel>
        </Button.ToolTip>
    </Button>






     

CustomGrid class is like:

 public class MyStackPanel:StackPanel
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new UIAutomationChildPeer(this);
    }

  
}
public class UIAutomationChildPeer : FrameworkElementAutomationPeer
{
    public UIAutomationChildPeer(FrameworkElement element):base(element)
    {

    }

    protected override string GetClassNameCore()
    {
        return "Additional Details";
    }
    protected override List<AutomationPeer> GetChildrenCore()
    {
        var childrenAutomationPeer = new List<AutomationPeer>();

        var owner = Owner as StackPanel;

        if (owner != null)
        {
            //owner.GotFocus += Owner_GotFocus;
            var childElements = owner.Children;// indName("myGrid", owner) as Grid;
            if (childElements != null && childElements.Count > 0)
            {
                foreach (TextBlock item in childElements)
                {
                        var headerTextBlockAutomationPeer = new TextAutomationPeer(item);
                    childrenAutomationPeer.Add(headerTextBlockAutomationPeer);

                }
            }

        }

        return childrenAutomationPeer;
        
    }
}

public class TextAutomationPeer : TextBlockAutomationPeer
{
    private StringBuilder detail = new StringBuilder();
    public UIElement Element { get { return Owner; } }

    public TextAutomationPeer(TextBlock owner) : base(owner)
    {
        if (!string.IsNullOrWhiteSpace(owner.Text.ToString()))
        {
            detail.Append(owner.Text.ToString());
        }
    }

    public override string ToString()
    {
        return detail.ToString();
    }

}

Have tried with manually triggering the focus event or setting Tab Index. Nothing brings out the result. Any leads for resolving this issue.

#UWP #WPF #Windows10

1

There are 1 answers

0
Roy Li - MSFT On

The controls that you put in the tooltip won't get focused so the narrator won't respond to them. This is the same for TextBlock.

Generally, we will use the AutomationProperties.HelpText Attached Property to add simple text to a control. The narrator will respond to the AutomationProperties.HelpText.