user1275513
user1275513

Reputation: 357

WPF White framework accessing custom property on custom control

Is there a way how to access custom property on custom control in WPF using White framework test ?

Let's say I have class like this:

public class MyButton : System.Windows.Controls.Button
{
    public MyButton()
    {

    }

    public string MyCustomButtonProp { get { return "MyButtonInfo"; } }
}

Is there a way how to access MyCustomButtonProp via White framework in a test ? I read how custom controls are handled (https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/) but that didn't lead me to conclusion how to access custom properties, only how to handle custom controls with nested controls. If I use standard White framework objects (Button in this case) I can interact with the button but that's not sufficient in my case.

Upvotes: 1

Views: 472

Answers (1)

Max Young
Max Young

Reputation: 1662

You would need to write your own AutomationPeer to expose the property. Then you would need to extend the White control to expose your custom property.

Overriding the AutomationPeer is not that bad since you might be able to just inherit from another AutomationPeer to get 90% of the functionality you need.

Here is an example of how to write a AutomationPeer. Here is another document I would take a look at which gives a much more broad overview of implementing the "server" side of UIA.

Upvotes: 0

Related Questions