Обработка изменения значения ProgressBar с помощью UIAutomation

Как я могу получать уведомления об изменении значения ProgressBar с помощью платформы .NET UIAutomation? Я не вижу такого свойства в классе AutomationElement.


person Peter    schedule 31.05.2014    source источник
comment
AutomationPropertyChangedEvent с ValuePattern.ValueProperty.Id не работает?   -  person Eric Brown    schedule 04.06.2014
comment
У вас есть пример кода?   -  person Peter    schedule 04.06.2014


Ответы (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);
    }
}
person Eric Brown    schedule 04.06.2014
comment
Я использую FlaUI для автоматизации. У меня есть индикатор выполнения WPF. Хотите повторить попытку, пока его видимость не будет свернута. Не удалось получить доступ к собственности. Помощь? - person Apoorv; 05.03.2020
comment
@Apoorv Я бы создал новый вопрос, показав, что у вас уже есть. - person Eric Brown; 05.03.2020
comment
stackoverflow.com/questions/60553908/ - person Apoorv; 06.03.2020