AccessibleObject implementation for custom controls
Asked Answered
B

1

9

I have a very simple controls library for Windows Forms and I am getting problems to implement accessibility.

I have a very simple Form with a member that contains a list of controls of my library, and I have overriden the CreateAccessibilityInstance:

public partial class Form1 : Form
{
    protected override AccessibleObject CreateAccessibilityInstance()
    {
        return new AccessibleForm(this);
    }

    public MyContainer MyContainer;

    public Form1()
    {
        InitializeComponent();
        MyContainer = new MyContainer();
        MyContainer.Controls.Add(new MyButton());
    }
}

The AccessibleForm class looks like:

public class AccessibleForm: Control.ControlAccessibleObject
{
    private Form1 form1;

    public AccessibleForm(Form1 owner):base(owner)
    {
        this.form1 = owner;
    }

    public override AccessibleObject GetChild(int index)
    {
        return this.form1.MyContainer.Controls[index].AccessibilityObject;
    }

    public override int GetChildCount()
    {
        return this.form1.MyContainer.Controls.Count() ;
    }
}

MyContanier and MyButton classes inherits from BaseControl, they are very easy:

public class BaseControl : Control
{
    protected override AccessibleObject CreateAccessibilityInstance()
    {
        return new AccessibleObject();
    }
}


public class MyContainer:BaseControl
{
    public List<BaseControl> Controls { get; set; }

    public MyContainer()
    {
        this.Controls = new List<BaseControl>();
    }
}

public class MyButton:BaseControl
{        
}

The point is that when I run the UIVerify tool to see if my controls are generating the correct structure I can not see them:

UIVerify Snapshot

Another point is, that if I modify the GetChild method from AccessibleForm class in this way:

public override AccessibleObject GetChild(int index)
{
    return new AccessibleObject();
    ////return this.form1.MyContainer.Controls[index].AccessibilityObject;
}

I can see a node on the UIVerify:

enter image description here

But modifying the GetChild method to return a custom accessible object it shows me nothing.

Why are not my controls on the tree?

I do not know what I am missing.

Bearcat answered 4/4, 2016 at 6:26 Comment(1)
Can you share some sample of source code, in order not to retype what you posted here?Mccusker
Z
2

Override Name,value,Role in AccessibleForm class

Zindman answered 8/5, 2018 at 5:23 Comment(1)
Thanks. For more info: the default implementation always returns null even if you set the property. Hence why you need to explicitly override it.Erotic

© 2022 - 2024 — McMap. All rights reserved.