处理进度与UIAutomation值变化(Handling ProgressBar's Va

2019-10-20 05:24发布

我怎样才能得到通知与.NET UIAutomation框架时进度值发生变化? 我没有看到在AutomationElement类这样的属性。

Answer 1:

我直接从画了这个样本MSDN文档 ,只改变属性:

AutomationPropertyChangedEventHandler propChangeHandler;
/// <summary> 
/// Adds a handler for property-changed event; in particular, a change in the value 
/// </summary> 
/// <param name="element">The UI Automation element whose state is being monitored.</param>
public void SubscribePropertyChange(AutomationElement element)
{
    Automation.AddAutomationPropertyChangedEventHandler(element, 
        TreeScope.Element, 
        propChangeHandler = new AutomationPropertyChangedEventHandler(OnPropertyChange),
        ValuePattern.ValueProperty);

}

/// <summary> 
/// Handler for property changes. 
/// </summary> 
/// <param name="src">The source whose properties changed.</param>
/// <param name="e">Event arguments.</param>
private void OnPropertyChange(object src, AutomationPropertyChangedEventArgs e)
{
    AutomationElement sourceElement = src as AutomationElement;
    if (e.Property == ValuePattern.ValueProperty)
    {
        // TODO: Do something with the new value.  
        // The element that raised the event can be identified by its runtime ID property.
    }
    else
    { 
        // TODO: Handle other property-changed events.
    }
}

public void UnsubscribePropertyChange(AutomationElement element)
{
    if (propChangeHandler != null)
    {
        Automation.RemoveAutomationPropertyChangedEventHandler(element, propChangeHandler);
    }
}


文章来源: Handling ProgressBar's Value change with UIAutomation