Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
625
UltraGrid: Custom ValueListItemUIElement - UI automation broken
posted

I have created a subclass for ValueListItemUIElement to handle some rare exceptions that occur in a mixed WinForms/WPF environment (I have an override for InitAppearance that calls the base class and catches exceptions that occur in this call chain). This all works pretty well so far. 

However, this seems to have broken UI automation and this is probably related to the way how I create and initialize the new instances. I used a CreationFilter (IUIElementCreationFilter) and in there I have the following section:

      public void AfterCreateChildElements(UIElement parent)
        {

            switch (parent)
            {
 ...
                 case ValueListItemContainerUIElement container:
                    {
                        // replace standard ValueListItemUIElement with our custom class that catches
                        // null reference exceptions
                        var newChildElements = parent.ChildElements.Select(
                            c =>
                                {
                                    if (c is ValueListItemUIElement valueListItemUIElement)
                                    {
                                        var newValueListItemUIElement = new SafeValueListItemUIElement(
                                            container,
                                            valueListItemUIElement.ValueListItem,
                                            valueListItemUIElement.IsMruItem,
                                            valueListItemUIElement.ListIndex)
                                        {
                                            Rect = valueListItemUIElement.Rect
                                        };

                                        return newValueListItemUIElement;
                                    }

                                    return null;
                                })
                            .Where(i => i != null)
                            .ToList();

                        parent.ChildElements.Clear();
                        parent.ChildElements.AddRange(newChildElements);
                        parent.DirtyChildElements(true);
                        break;
                    }

I assume something is missing in my initialization of the new instances. In the debugger I noticed that the AccessibilityInstance of the new entities has an empty (0,0,0,0) BoundingRectangle and Bounds property.

Does anyone have any clue what might be missing here?