1

How can I be notified when ProgressBar's Value changes with .NET UIAutomation framework? I dont see such property in AutomationElement class.

Peter
  • 36
  • 9

1 Answers1

1

I drew this sample directly from the MSDN documentation, changing only the property:

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);
    }
}
Eric Brown
  • 13,774
  • 7
  • 30
  • 71
  • I am using FlaUI for Automation. I have a WPF progress bar. Want to Retry until its visibiility is Collapsed. Not able to access the property. Help? – Apoorv Mar 05 '20 at 16:23
  • @Apoorv I'd create a new question, showing what you have already. – Eric Brown Mar 05 '20 at 19:14
  • https://stackoverflow.com/questions/60553908/getting-the-visibility-of-a-progress-bar-in-a-wpf-application-using-flaui-automa – Apoorv Mar 05 '20 at 21:04