WPF的AutomationPeer崩溃在触摸屏设备 [英] WPF AutomationPeer Crash on TouchScreen Devices

查看:638
本文介绍了WPF的AutomationPeer崩溃在触摸屏设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个WPF应用程序。它适用于台式机完全正常,但此刻的应用程序运行在它崩溃触摸屏。我已经关闭触摸屏的流程和应用程序的工作完全没问题。我不知道有没有人发现了一个更好的修复,而不是禁用触摸屏的过程,因为这将不是微软Surface或和Windows平板电脑上运行。

I created a WPF application. It works completely fine on desktops but the moment the application is ran on a touchscreen it crashes. I've turned off touchscreen processes and the application worked completely fine. I'm wondering has anyone found a "better" fix than to disable touchscreen processes, as this would not work on the microsoft surface or and windows tablet.

我目前使用.NET 4.5

I'm currently using .Net 4.5

推荐答案

我有有许多问题与WPF 的AutomationPeer 了。

I have had many problems with WPF AutomationPeer too.

您也许可以迫使你的WPF UI元素为您解决问题使用通过不返回子控件的AutomationPeers行为有所不同,以默认的自定义的AutomationPeer。这可能会阻止任何UI自动化的东西的工作,但希望在你的情况,因为在我,你是不是使用UI自动化..

You might be able to solve your problem by forcing your WPF UI elements to use a custom AutomationPeer that behaves differently to the default one by not returning AutomationPeers of child controls. This might stop any UI automation stuff working, but hopefully in your case, as in mine, you are not using UI automation..

创建继承的自定义自动化同级类从 FrameworkElementAutomationPeer 并覆盖 GetChildrenCore 方法返回一个空的列表,而不是孩子控制自动化同行。这应该停止问题存在的,当一些试图通过AutomationPeers的树进行迭代。

Create a custom automation peer class that inherits from FrameworkElementAutomationPeer and overrides the GetChildrenCore method, to return an empty list instead of the child control automation peers. This should stop problems occuring when something attempts to iterate through the tree of AutomationPeers.

另外重写 GetAutomationControlTypeCore 来指定你会使用自动化控制输入对上。在这个例子中,我通过了 AutomationControlType 作为构造函数的参数。如果你申请你的自定义自动化同级到Windows它应该解决您的问题,我觉得根元素用来返回所有的孩子。

Also override the GetAutomationControlTypeCore to specify the control type that you will use the automation peer on. In this example I am passing the AutomationControlType as a constructor parameter. If you apply your custom automation peer to your Windows it should solve your problems as I think the root element is used to return all children.

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>();
    }
}

要使用自定义自动化同级覆盖了<$ C在你的UI元素如:$ C> OnCreateAutomationPeer 方法窗口:

To use the custom automation peer override the OnCreateAutomationPeer method in your UI element e.g. Window:

protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
    return new MockAutomationPeer(this, AutomationControlType.Window);
}

这篇关于WPF的AutomationPeer崩溃在触摸屏设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆