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