Testing a UserControl

Apr 23, 2010 at 2:17 AM


I having trouble testing a UserControl I have created. I think I'm missing a step.

What I'm doing is:

1) I create a custom control ... nothing special:

// UserControl

public partial class MyCustomControl : UserControl


// XAML on page:

 <MyNamespace:MyCustomControl x:Name="fred" />

It works, I can see it on the page.

2) I created a custom tester:

    public class MyCustomControl : CustomUIItem
        public MyCustomControl (AutomationElement automationElement, ActionListener actionListener)
            : base(automationElement, actionListener)

        protected MyCustomControl () { }

3) I try to use the tester:

            var thingy = _document.Get<MyCustomControl>("fred");


Trouble is that thingy is always null!

Me thinks I've missed something :-)


Rob Smyth






Apr 23, 2010 at 5:42 AM



what does UISpy or UIAVerify saysw to your control?


use always uid to set the automationID, so you can change the name but the uid will be the same.

if the tools see your control



AutomationElement element = _document.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AuutomationidProperty, "fred");

MyCustomControl control = new MyCustomControl(element, _document.ActionListener);