首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows旁白器是否正在读取自定义工具提示内容?

Windows旁白器是否正在读取自定义工具提示内容?
EN

Stack Overflow用户
提问于 2022-04-08 11:00:02
回答 1查看 159关注 0票数 0

我有一个要求阅读内容的复杂工具提示内容的WPF或UWP应用程序的叙述。我正面临着阅读工具提示可见内容的挑战。试图重写AutomationPeer类和the方法。但没有运气:

我的XAML UI如下:

代码语言:javascript
复制
 <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类类似于:

代码语言:javascript
复制
 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

EN

回答 1

Stack Overflow用户

发布于 2022-04-13 02:13:56

你放在工具提示中的控件不会集中注意力,所以叙述者不会响应它们。这对于TextBlock也是一样的。

通常,我们将使用AutomationProperties.HelpText附着特性向控件添加简单文本。叙述者将对AutomationProperties.HelpText作出回应。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71795851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档