Silverlight User Control Automation??

Jun 29, 2010 at 4:55 AM

Hi,

I have created a custom control in silverlight. But when i try to get it by automation id it always returns null.

Am i missing something or white lacks this feature for silverlight?

My User Control

public partial class MyCustomControl : UserControl
    {
        public MyCustomControl()
        {
            InitializeComponent();
        }


        public string MyTitle
        {
            get { return (string)GetValue(MyTitleProperty); }
            set { SetValue(MyTitleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MyTitle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MyTitleProperty =
            DependencyProperty.Register("MyTitle", typeof(string), typeof(MyCustomControl), null);


    }

TestCase and CustomUIItem

[TestMethod]
        public void CustomControlTest()
        {

            browserWindow = InternetExplorer.Launch("http://localhost:2463/SampleApplicationTestPage.aspx", "SampleApplication - Windows Internet Explorer");
            browserWindow.WaitWhileBusy();
            SilverlightDocument document = browserWindow.SilverlightDocument;

            //Approach 1
            IUIItem element = document.Get(SearchCriteria.ByControlType(typeof(MyCustomControl)));

            //Approach 2
            MyCustomControl MyCustomControl = document.Get<MyCustomControl>("MyCustom");

            //Approach 3
            IUIItem custom = document.Get(SearchCriteria.ByAutomationId("MyCustom"));
            MyCustomControl MyCustomCtrl = null;
            if (custom != null)
            {
                MyCustomCtrl = custom as MyCustomControl;
            }           
          

        }
[ControlTypeMapping(CustomUIItemType.Custom)]
    public class MyCustomControl : CustomUIItem
    {
        // Implement these two constructors. The order of parameters should be same.
        public MyCustomControl(AutomationElement automationElement, ActionListener actionListener)
            : base(automationElement, actionListener)
        {
        }

        //Empty constructor is mandatory with protected or public access modifier.
        protected MyCustomControl() { }
    }
Jun 29, 2010 at 5:46 AM
Edited Jun 29, 2010 at 7:20 AM

Hi

 

I have no experience with silverlight, but in WPF works

 

 

//Aproach 4

MyCustomControl myCustomControl =null;

AutomationElement element = document.GetElementt(SearchCriteria.ByAutomationId("MyCustom"));

if(element !=null)
{

  myCustomControl = new MyCustomControl(element, document.ActionListener);
}

 

 

Throndorin

Jun 29, 2010 at 7:02 AM

This is also returning null

Jun 29, 2010 at 7:21 AM

element is null?

 

Jun 29, 2010 at 11:43 AM

yes

Jun 29, 2010 at 12:25 PM

ok

does UISpy or UIAVerify see this custom control ?

 

Throndorin