首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF AutomationPeer在TouchScreen设备上崩溃

WPF AutomationPeer在TouchScreen设备上崩溃
EN

Stack Overflow用户
提问于 2016-03-01 16:00:40
回答 1查看 1.2K关注 0票数 10

我创建了一个WPF应用程序。它在桌面上完全正常工作,但当应用程序在触摸屏上运行时,它就会崩溃。我关闭了触摸屏进程,应用程序运行得非常好。我想知道是否有人发现了比禁用触摸屏进程更好的修复方法,因为这在微软表面或windows平板电脑上是行不通的。

我目前使用的是.Net 4.5

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-27 21:20:34

我对WPF的AutomationPeer也有很多问题。

您可以通过强制WPF UI元素使用与默认AutomationPeer不同的自定义AutomationPeers来解决问题,方法是不返回子控件的AutomationPeers。这可能会停止任何UI自动化工作,但希望在您的情况下,就像我的情况一样,您没有使用UI自动化。

创建一个从FrameworkElementAutomationPeer继承并重写GetChildrenCore方法的自定义自动化对等类,以返回一个空列表而不是子控件自动化对等点。这样,当有东西试图遍历AutomationPeers树时,问题就会停止发生。

还将重写GetAutomationControlTypeCore以指定将使用自动化对等点的控件类型。在本例中,我将AutomationControlType作为构造函数参数传递。如果您将您的自定义自动化对等程序应用于您的Windows,它将解决您的问题,因为我认为根元素用于返回所有子元素。

代码语言:javascript
复制
public class MockAutomationPeer : FrameworkElementAutomationPeer
{
    AutomationControlType _controlType;

    public MockAutomationPeer(FrameworkElement owner, AutomationControlType controlType)
        : base(owner)
    {
        _controlType = controlType;
    }

    protected override string GetNameCore()
    {
        return "MockAutomationPeer";
    }

    protected override AutomationControlType GetAutomationControlTypeCore()
    {
        return _controlType;
    }

    protected override List<AutomationPeer> GetChildrenCore()
    {
        return new List<AutomationPeer>();
    }
}

要使用自定义的自动化对等体覆盖UI元素中的OnCreateAutomationPeer方法,例如窗口:

代码语言:javascript
复制
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
    return new MockAutomationPeer(this, AutomationControlType.Window);
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35727592

复制
相关文章

相似问题

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