Windows叙述者没有读取自定义工具提示内容?
我需要通过叙述者阅读WPF或UWP应用程序的复杂工具提示内容的内容。我面临着阅读工具提示可见的内容的挑战。试图覆盖自动化类和那里的方法。但是没有运气:(
我的XAML UI在下面:
<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类就像:
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();
}
}
手动触发焦点事件或设置选项卡索引。没有任何结果。解决此问题的任何线索。
尝试
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您放入工具提示中的控件不会获得焦点,因此旁白不会对它们做出响应。这与
TextBlock
相同。一般来说,我们会使用 AutomationProperties.HelpText 附加属性 用于向控件添加简单文本。旁白将响应
AutomationProperties.HelpText
。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
.