Windows叙述者没有读取自定义工具提示内容?

发布于 2025-01-20 00:40:01 字数 2536 浏览 1 评论 0原文

我需要通过叙述者阅读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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁 2025-01-27 00:40:01

您放入工具提示中的控件不会获得焦点,因此旁白不会对它们做出响应。这与 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文