我创建了一个WPF应用程序。它在台式机上完全可以正常工作,但是一旦在触摸屏上运行该应用程序,它就会崩溃。我已经关闭了触摸屏进程,该应用程序运行正常。我想知道有没有人能找到比禁用触摸屏过程更好的修复程序,因为这在Microsoft Surface或Windows Tablet上不起作用。
我目前正在使用.Net 4.5
我也有很多WPF问题AutomationPeer
。
您可以通过不返回子控件的AutomationPeers来强制WPF UI元素使用行为与默认行为不同的自定义AutomationPeer来解决问题。这可能会停止任何UI自动化工作,但是希望您能像在我的情况下那样,不使用UI自动化。
创建一个自定义自动化对等类,该类继承FrameworkElementAutomationPeer
并覆盖该GetChildrenCore
方法,以返回一个空列表,而不是子控件自动化对等。当某些东西尝试遍历AutomationPeers树时,这应该可以避免发生问题。
还要覆盖,GetAutomationControlTypeCore
以指定将在其上使用自动化对等方的控件类型。在此示例中,我将AutomationControlType
as作为构造函数参数传递。如果您将自定义自动化对等体应用于Windows,则应该解决您的问题,因为我认为root元素用于返回所有子项。
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>();
}
}
要使用自定义自动化对等方OnCreateAutomationPeer
,请在您的UI元素(例如Window)中覆盖该方法:
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new MockAutomationPeer(this, AutomationControlType.Window);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句