UI Automation Button Style Enabled

Posted by Victor Gaspar on Stack Overflow See other posts from Stack Overflow or by Victor Gaspar
Published on 2010-04-21T15:04:13Z Indexed on 2010/04/23 14:23 UTC
Read the original article Hit count: 339

Filed under:
|
|

Hi,

I'm evaluating UI Automation for UI testing for that I have a WPF application with the following button defined:

<Button Style="{DynamicResource ButtonStyle}" x:Name="MyBtn"/>

when I need to visually disable the button I just change the style so the user is aware that the button is disabled (the colour changed) but still the button is internally enabled so I can still launch the OnClick event in order to show a message when the user clicks on a "disabled" button.

Now the problem is that I don't know how to check from UI Automation the Style that its currently applied i.e. if the button is disabled or enabled. Do you know how can I do that?

In a normal situation I should do something like that:

Automation.Condition cEBtn = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyBtn");

AutomationElement mybtnElement = appRegraceElement.FindFirst(TreeScope.Children, cEBtn);

bool disMyBtn = (bool)mybtnElement .GetCurrentPropertyValue(AutomationElement.IsEnabledProperty);

but in my case the button is always enabled therefore I need to check the Style applied to the button.

Thank you very much.

Best regards

© Stack Overflow or respective owner

Related posts about uiautomation

Related posts about c#