我创建了一个WPF应用程序。它在桌面上运行得非常好,但应用程序在运行在触摸屏上的应用程序崩溃了。我关闭了触摸屏流程,应用程序运行良好。我不知道有没有人发现了一个“更好”的修复,而不是禁用触摸屏的过程,因为这不是微软的Surface或和Windows平板电脑上运行。WPF的AutomationPeer崩溃在触摸屏设备
我目前使用.NET 4.5
我创建了一个WPF应用程序。它在桌面上运行得非常好,但应用程序在运行在触摸屏上的应用程序崩溃了。我关闭了触摸屏流程,应用程序运行良好。我不知道有没有人发现了一个“更好”的修复,而不是禁用触摸屏的过程,因为这不是微软的Surface或和Windows平板电脑上运行。WPF的AutomationPeer崩溃在触摸屏设备
我目前使用.NET 4.5
我曾与WPF AutomationPeer
太多的问题。
您可能能够通过迫使你的WPF UI元素使用的是通过不返回子控件的AutomationPeers表现不同的默认一个自定义的AutomationPeer解决您的问题。这可能会阻止任何UI自动化的东西的工作,但希望在你的情况,因为在我,你是不是使用UI自动化..
创建从FrameworkElementAutomationPeer
继承和覆盖GetChildrenCore
方法定制自动化同级类,返回一个空列表而不是子控制自动化同行。当某些事情试图通过AutomationPeers树进行迭代时,这应该可以避免发生问题。
而且覆盖GetAutomationControlTypeCore
指定要使用的自动化同级控件类型。在这个例子中,我通过AutomationControlType
作为构造函数参数。如果你申请你的自定义自动对您的Windows应该解决您的问题,我认为根元素用于返回所有儿童。
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
方法,例如,窗口:
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new MockAutomationPeer(this, AutomationControlType.Window);
}
投票的任何特定原因?我试图回答这个问题:“有没有人发现一个”更好“的解决方案,而不是禁用触摸屏进程”。如果我的回答没有用,请说明您的理由。 –
喜@Glen托马斯感谢您抽出时间来回答。这已解决了我的自动化对等问题。 – Master
你可以显示在代码中你得到一个异常抛出? – Terrance