我有一个要求阅读内容的复杂工具提示内容的WPF或UWP应用程序的叙述。我正面临着阅读工具提示可见内容的挑战。试图重写AutomationPeer类和the方法。但没有运气:
我的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();
}
}尝试手动触发焦点事件或设置Tab索引。没有什么能带来结果。任何解决这个问题的线索。
#UWP #WPF #Windows10 10
发布于 2022-04-13 02:13:56
你放在工具提示中的控件不会集中注意力,所以叙述者不会响应它们。这对于TextBlock也是一样的。
通常,我们将使用AutomationProperties.HelpText附着特性向控件添加简单文本。叙述者将对AutomationProperties.HelpText作出回应。
https://stackoverflow.com/questions/71795851
复制相似问题