本文整理汇总了C#中System.Windows.UIElement.CreateAutomationPeer方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.CreateAutomationPeer方法的具体用法?C# UIElement.CreateAutomationPeer怎么用?C# UIElement.CreateAutomationPeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.UIElement
的用法示例。
在下文中一共展示了UIElement.CreateAutomationPeer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePeerForElement
///<summary>
/// This static helper creates an AutomationPeer for the specified element and
/// caches it - that means the created peer is going to live long and shadow the
/// element for its lifetime. The peer will be used by Automation to proxy the element, and
/// to fire events to the Automation when something happens with the element.
/// The created peer is returned from this method and also from subsequent calls to this method
/// and <seealso cref="FromElement"/>. The type of the peer is determined by the
/// <seealso cref="UIElement.OnCreateAutomationPeer"/> virtual callback. If UIElement does not
/// implement the callback, there will be no peer and this method will return 'null' (in other
/// words, there is no such thing as a 'default peer').
///</summary>
public static AutomationPeer CreatePeerForElement(UIElement element)
{
if(element == null)
{
throw new ArgumentNullException("element");
}
return element.CreateAutomationPeer();
}
示例2: CreatePeerForElement
public static AutomationPeer CreatePeerForElement (UIElement element)
{
if (element == null)
throw new ArgumentNullException ("element");
if (element.AutomationPeer == null) {
element.AutomationPeer = element.CreateAutomationPeer ();
// We need to cache old values to raise PropertyChanged events
// when calling AutomationPeer.InvalidatePeer()
if (element.AutomationPeer != null)
element.AutomationPeer.CacheMainProperties ();
}
return element.AutomationPeer;
}